Issue #10063 has been updated by Matthaus Litteken.

Status changed from Needs More Information to Accepted
Keywords changed from cron ordering to cron ordering parsedfile

I was able to reproduce this. I think you are correct, it seems like 
parsedfile, which cron uses, does a prefetch on the cron before running the 
exec or evaluating the cron resource.

    [root@localhost /]# crontab -l
    # HEADER: This file was autogenerated at Tue Nov 15 10:53:27 -0800 2011 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.
    26 3 * * * /usr/local/sbin/myjob
    [root@localhost /]# puppet apply broken_cron.pp 
    notice: /Stage[main]/Broken_cron/Exec[crontab -l|grep -v myjob|crontab 
-]/returns: executed successfully
    notice: /Stage[main]/Broken_cron/Cron[myjob]/ensure: created
    notice: Finished catalog run in 0.31 seconds
    [root@localhost /]# crontab -l
    # HEADER: This file was autogenerated at Tue Nov 22 09:30:34 -0800 2011 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.
    26 3 * * * /usr/local/sbin/myjob
    # Puppet Name: myjob
    22 5 * * * /usr/local/sbin/myjob


Another interesting situation (and unexpected result). If you have the same 
cronjob as you are trying to create, but without the puppet comment header, 
running the above manifest will remove the cron entry entirely. Output 
follows...


    [root@localhost /]# crontab -l
    # HEADER: This file was autogenerated at Tue Nov 15 10:53:27 -0800 2011 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.
    22 5 * * * /usr/local/sbin/myjob
    [root@localhost /]# puppet apply broken_cron.pp 
    notice: /Stage[main]/Broken_cron/Exec[crontab -l|grep -v myjob|crontab 
-]/returns: executed successfully
    notice: Finished catalog run in 0.28 seconds
    [root@localhost /]# crontab -l
    # HEADER: This file was autogenerated at Tue Nov 15 10:53:27 -0800 2011 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.
    [root@localhost /]# 
----------------------------------------
Bug #10063: cron resource violates resource ordering
https://projects.puppetlabs.com/issues/10063

Author: Igor .
Status: Accepted
Priority: Normal
Assignee: 
Category: cron
Target version: 
Affected Puppet version: 2.7.3
Keywords: cron ordering parsedfile
Branch: 


Consider the following class
<pre> 
class broken_cron {
        cron { 'myjob':
                command => "/usr/local/sbin/myjob",
                user => root,
                minute => "22"
                hour => "5"
                ensure => present
        }
 
        # Try and cleanup crontab -- this is broken in a rather surprising way!
        
        exec { 'crontab -l|grep -v myjob|crontab -':
                unless => "crontab -l|grep '^# Puppet Name: myjob'",
                path => "/bin:/usr/bin",
                before => Cron['myjob']
                }
 
}
</pre>

if this applied when crontab already contains myjob but with different time 
settings than specified in the cron resource, crontab will end up containing 
the job twice. It seems cron type is prefetching the contents of crontab before 
the exec runs despite the explicit ordering.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to