[Pkg-puppet-devel] Bug#529224: Cron job removal

Stig Sandbeck Mathisen ssm at debian.org
Mon Aug 2 11:18:45 UTC 2010


Jayen <jashar at alumni.cmu.edu> writes:

> The cron job was not added by puppet, but was around before we started
> using puppet.  We're trying to clean up some of the old cron jobs
> using puppet.

That won't work with puppet's cron provider, unfortunately. It will only
remove cron jobs it identifies as one of its own.

To be more specific: It uses a commented header to identify the cron
job.  As you see, the hour and minute does not need to be specified to
remove the cron job:

,----[ Existing crontab before puppet ]
| ssm at mavis:~ :) $ crontab -l
| # m h  dom mon dow   command
| 08  08 *   *   *     /home/ssm/bin/update-schroots
`----

,----[ Add new crontab with puppet ]
| $ puppet -e 'cron{"update-schroots": command => "/home/ssm/bin/update-schroots", minute => fqdn_rand(59), hour=> fqdn_rand(23), ensure => present }'
| notice: /Stage[main]//Cron[update-schroots]/ensure: created
| ssm at mavis:~ :) $ crontab -l
| # HEADER: This file was autogenerated at Mon Aug 02 11:33:18 +0200 2010 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.
| # m h  dom mon dow   command
| 08 08 * * * /home/ssm/bin/update-schroots
| # Puppet Name: update-schroots
| 25 17 * * * /home/ssm/bin/update-schroots
`----

,----[ Remove crontab with puppet ]
| ssm at mavis:~ :) $ puppet -e 'cron{"update-schroots": command => "/home/ssm/bin/update-schroots", ensure => absent }'
| notice: /Stage[main]//Cron[update-schroots]/ensure: removed
| ssm at mavis:~ :) $ crontab -l
| # HEADER: This file was autogenerated at Mon Aug 02 11:34:37 +0200 2010 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.
| # m h  dom mon dow   command
| 08 08 * * * /home/ssm/bin/update-schroots
`----

,----[ Remove crontab with puppet (again) ]
| ssm at mavis:~ :) $ puppet -e 'cron{"update-schroots": command => "/home/ssm/bin/update-schroots", ensure => absent }'
| ssm at mavis:~ :) $ crontab -l
| # HEADER: This file was autogenerated at Mon Aug 02 11:34:37 +0200 2010 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.
| # m h  dom mon dow   command
| 08 08 * * * /home/ssm/bin/update-schroots
`----

You could, instead, use a definition to remove a line matching your
commands in the crontab file with a define like the one found at
http://git.black.co.at/?p=module-common;a=blob_plain;f=manifests/defines/line.pp

-- 
Stig Sandbeck Mathisen
                      ooo, shiny!





More information about the Pkg-puppet-devel mailing list