we write about the things we build and the things we consume
Adam Millican

cron jobs and puppet

A recent piece of work I did was to write a python script and set it up to run on an instance every night. Due to the setup of how our instances work, the script and configuration for it to run needed to be set up on Puppet.


Puppet is a software configuration management tool. It has it’s own declarative language for system configuration, and is open source. Essentially, when puppet is run on an instance, the configurations are set to whatever we have on our repository, allowing us to keep our configurations synced to what we want across all of our instances.

Puppet can control what goes where too, so while it may be run on all instances, it will only install my script to the instance that is going to run it, because that’s how it was configured.

cron jobs

Cron is a software utility used to schedule jobs to trigger at certain times. The time, date, or even day of the week can be specified, so that the job will run exactly when the developer wants it to run, if configured correctly. The timing of the job is specified by 5 numbers (or *s) separated by spaces, in the following format:

┌───────────────────── minute
│ ┌─────────────────── hour
│ │ ┌───────────────── day of month
│ │ │ ┌─────────────── month
│ │ │ │ ┌───────────── day of week
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │


0 0 * * * script.py Every Midnight
30 9 * 1 * script.py 9.30 am every day in January
0 23 14 2 * script.py 11 pm valentines day
0 0 * * 0 script.py Every Sunday at midnight

puppet deployment

The following Puppet configuration will tell it to put your script from the repo onto the host you want it (specified by which file this configuration command is in) in the directory you want:

file { "location to put file":
source => "location of file in puppet repo",
mode => 755,

The following Puppet configuration will setup a cron job on the host, specified by which file this configuration command is in, to run the script or command at the time specified by the user specified.

cron { "job-name":
command => 'command or script location',
user => user,
hour => 0,
minute => 0,
weekday => "*",
require => File['location of file']

And that’s it. With these configuration commands in the right place, Puppet will set your script up to run where specified, and when specified.

If you enjoyed the read, drop us a comment below or share the article, follow us on Twitter or subscribe to our #MetaBeers newsletter. Before you go, grab a PDF of the article, and let us know if it’s time we worked together.

blog comments powered by Disqus
sign up to #metabeers