Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

If you are a professional associated with system and infrastructure management, looking at automated infrastructure and deployments, then this book is for you. No prior experience of Salt is required.
Table of Contents (13 chapters)
12
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:...