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.
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).
What are the best practices in this situation?
Some solutions I've thought of:
{% set mysqlrunning = salt['service.status'](mysql_service) %}
{% if mysqlrunning %}
<rest of state file>
{% endif %}
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).
What are the best practices in this situation?
Usually one should be easy on the jinja in states, but use jinja maps.
In your example case, I would use require
mysqld:
service.running
insert_sql:
cmd.run:
- name: mysql < /tmp/src.sql
- require:
- service: mysqld
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With