Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

Table of Contents (18 chapters)
Salt Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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...

  1. Configure two new minions called salt-minion-1 and salt-minion-2.

  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: '*'
  3. Edit the /etc/salt/master.d/reactor.conf file to have the following entries:

    reactor:
    
      - 'salt/minion/*/start':
        - /opt/salt/staging/event/cron.sls
  4. 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:...