Installing/Updating Cron entries using Puppet Cron Resource

Puppet comes with a builtin cron resource which installs and manages cron entries. More of this resource is available at
https://docs.puppetlabs.com/puppet/latest/reference/types/cron.html

A cron resource with some of its attributes are


cron { 'resource title':
  name        => # The symbolic name of the cron job.  
  ensure      => # The basic property that the resource should be...
  command     => # The command to execute in the cron job.  
  environment => # Any environment settings associated with this...
  hour        => # The hour at which to run the cron job. Optional; 
  minute      => # The minute at which to run the cron job...
  month       => # The month of the year.  Optional; if specified...
  monthday    => # The day of the month on which to run the...
  provider    => # The specific backend to use for this `cron...
  special     => # A special value such as 'reboot' or 'annually'...
  target      => # The name of the crontab file in which the cron...
  user        => # The user who owns the cron job.  This user must...
  weekday     => # The weekday on which to run the command...
  # ...plus any applicable metaparameters.
}


An example of using cron resource is as follows:

Example 1:
               cron { 'logrotate':
               command => '/usr/sbin/logrotate',
               user    => 'root',
               hour    => 2,
               minute  => 0,
             }
 
This will create a cron entry as follows: 

# id
uid=0(root) gid=0(root) groups=0(root) 
 
# crontab -l
# HEADER: This file was autogenerated at Tue Mar 29 11:02:53 +0530 2016 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: logrotate
0 2 * * * /usr/sbin/logrotate
Example 2:

             node 'node2.example.com','node3.example.com'{
                 cron { 'logrotate':
                 command => '/usr/sbin/logrotate',
                 user    => 'root',
                 hour    => [2,4,6],
                 minute  => '*/10',
               }
             }
 
This will create a cron entry for user root as follows :
 
   */10 2,4,6 * * * /usr/sbin/logrotate


Comments

Popular posts from this blog

PSSH : Parallel SSH to execute commands on a number of hosts

How to add check_http as a service in Nagios Monitoring using NRPE

Configuring Nagios to monitor services using NRPE