There are numerous occasions, no matter which infrastructure tier we work in, that we need to run automated tasks at some point of the day, week, month, and so on. In Linux systems, this functionality is achieved with cron. In this module, you will learn how to configure cron jobs using Salt modules.
We will use the salt-minion
minion that we configured in the previous recipe.
Create a new state called
cron
in the staging environment.Create and edit the
/opt/salt-cookbook/staging/cron/init.sls
file to have the following entries:clean_tomcat_logs: cron.present: - name: find /opt/apache-tomcat-6.0.43/logs/ -mtime +30 -exec rm -rf {} \; - user: root - minute: 00 - hour: 01 - daymonth: '*' - month: '*' - dayweek: '*'
Apply the state to the minion:
[root@salt-master ~]# salt 'salt-minion' state.sls cron saltenv=staging salt-minion: ---------- ID: clean_tomcat_logs Function: cron.present Name: find /opt/apache...