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 state modules

In the previous recipe, you learned about how you can use execution modules to perform configuration tasks in Salt. In this recipe, you are going to learn about of what state modules are and how to use them.

How to do it...

We will use the same minion and the same example as the previous recipe, but we will do the same task using state modules.

  1. Create a new state in the staging environment called cron by creating a new directory called cron and create a file in it called init.sls.
  2. Edit the init.sls file to have the following contents:
    find /var/log/ -mtime +30 -exec rm -rf {] \;:
      cron.present:
        - user: root
        - minute: 00
        - hour: 12
        - daymonth: '*'
        - month: '*'
        - dayweek: '*'
  3. Run the following command to apply the state to the minion:
    [root@salt-master  ~]# salt 'stgdc1log01' state.sls cron saltenv=staging
    stgdc1log01:
    ----------
              ID: find /var/log/ -mtime +30 -exec rm -rf {] \;
        Function: cron.present...