SaltStack has a pretty cool feature where you can manage your systems' crontabs from a central location. You can keep them in state SLS files and look them up via salt cron exectuion module. With a little bit of extra work, you can also keep the crons in pillars and feed them to your systems (that's something that I will certainly have to experiment with that later on). Even with base functionality, this is a pretty cool thing that should help you with truly automating your environment to the point where you will rarely have to log into a server to perform management duties.
Let's set up a basic crontab in Salt and distribute it to one of our minions just to get a basic idea how this all works.
Create a directory for your cron and an empty cron SLS file:
mkdir /srv/salt/states/cron cd /srv/salt/states/cron vim testcronjob.sls
Add the following to your testcronjob.sls file:
bash /opt/scripts/randomscript.sh: - cron.present: - user: root - minute: '*/2'
This will execute
bash /opt/scripts/randomscript.sh command every 2
minutes. You can also specify standard UNIX timing values via:
- minute: 0 - hour: 12 - daymonth: 6 - month: 4 - dayweek: 4
By default, if you don't specify a timing value, Salt will implement * for each value in the schedule.
You can implement the cron via:
salt 'testmachine01' state.sls cron.testcronjob
And you can view it by:
salt 'testmachine01' cron.list_tab root
You can find more information about managing crontabs in Salt below:
Salt cron state module:
Salt cron execution module: