Using reactors for Salt tasks
Now that we are aware of how the event and the reactor systems work in Salt, we can go ahead and look into some more advanced configurations involving using them to perform Salt tasks. In this recipe, we will learn how to perform a state run based on Salt events.
How to do it...
Configure two new minions called
salt-minion-1
andsalt-minion-2
.On the master, configure a new state module called
cron
in the staging environment and populate the/opt/salt/staging/cron/init.sls
file with the following entries:find /var/log/ -mtime +30 -exec rm -rf {] \;: cron.present: - user: root - minute: 00 - hour: 12 - daymonth: '*' - month: '*' - dayweek: '*'
Edit the
/etc/salt/master.d/reactor.conf
file to have the following entries:reactor: - 'salt/minion/*/start': - /opt/salt/staging/event/cron.sls
Create and edit
/opt/salt/staging/event/cron.sls
to have the following entries:{% if data['id'] == 'salt-minion-1' %} state_run: local.state.sls:...