Puppet: Creating Cronjobs via a manifest

Creating cron jobs via Puppet is fairly easy and well explained in available docs. However, I had some trouble adding cron jobs that needed to run at 2 different times a day.

Normal cron behavior is that you just enter a , in between your 2 timestamps and everything is done.

Eg something like this:

0 23,5 * * * /usr/bin/php5 /home/nicovs/update_cron.php

Now, when creating a cronjob with Puppet, you’d think that you can just type

hour  => "23,5",

in your manifest. The answer is: nope!

This is the error you’ll get:

err: Failed to apply catalog: Parameter hour failed: 23,5 is not a valid hour at /etc/puppet/manifests/nodes.pp:5

In the example below you’ll see that you have to use array’s to define your cron schedule:

cron { 'update_cron':
    ensure  => 'present',
    command => '/usr/bin/php5 /home/nicovs/update_cron.php',
    user => 'nicovs', 
    hour => [ 23, 5 ], 
    minute => '30', 
}

If you want to schedule this command to run every hour, your can use this however:

hour  => "*/1",

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top