title: Conditional Salt State
body: <p>I have a scenario where I need to take an action if another service is already running.  Specifically, I want to install snmp monitoring if, for example, mysql is already running.</p>
  
  <p>I know the "right" way to do this is to install mysql and its monitoring both based on pillar data, grain data, or some other top file filtering.  However, in this scenario, mysql is being installed outside of configuration management (eg, an MSP has clients that install mysql but then rely on the hosting provider to configure monitoring). </p>
  
  <p><strong>What are the best practices in this situation?</strong></p>
  
  <p>Some solutions I've thought of:</p>
  
  <ol>
  <li>Create a custom grain that lists services that are running. </li>
  <li>Use the unless/only if (and a map file for different the OS distributions)</li>
  <li>A Beacon (stating that the service is running) and a reactor (to deploy)</li>
  <li>Calling the service.status execution module in jinja in the state file, such as:</li>
  </ol>
  
  <p><code>{% set mysqlrunning = salt['service.status'](mysql_service) %}
  {% if mysqlrunning %}
  &lt;rest of state file&gt;
  {% endif %}</code></p>
  
  <p>While #4 seems simple enough, I am afraid it will be slow and use a lot of system resources in a large deployment (1000's of servers).</p>
  
  <p><strong>What are the best practices in this situation?</strong></p>