I'm trying to get a cron entry to exist based on the contents of a file.

I tried this:

    exec { "check-cron":
        command => "/bin/echo",
        logoutput => true,
        onlyif => "/bin/grep 'crontab' /etc/crontab.txt"
    }
    cron { exec-date:
        require => Exec["check-cron"],
        ensure => "present",
        command => "date >> /tmp/date.log",
        user => "root",
        minute => "*/10"
    }

My grep returns a value of 2 because /etc/crontab.txt does not exist:
# /bin/grep 'crontab' /etc/crontab.txt
grep: /etc/crontab.txt: No such file or directory
# echo $?
2

and yet puppet wants to install the crontab:
# /usr/sbin/puppetd --test --noop
info: Caching catalog at /var/lib/puppet/localconfig.yaml
notice: Starting catalog run
notice: //Cron[exec-date]/ensure: is absent, should be present (noop)
notice: Finished catalog run in 4.22 seconds

Once I put the text in /etc/crontab.txt, the logic gets reversed:

# echo crontab >> /etc/crontab.txt
# /usr/sbin/puppetd  --test --noop
info: Caching catalog at /var/lib/puppet/localconfig.yaml
notice: Starting catalog run
notice: //Exec[check-cron]/returns: is notrun, should be 0 (noop)
notice: //Cron[exec-date]/ensure: is absent, should be present (noop)
notice: Finished catalog run in 4.27 seconds

According to the documentation on onlyif:

If this parameter is set, then this exec will only run if the command
returns 0.

I'm stumped. And I may not be approaching this in the right way. Any
pointers would be appreciated. Also, the logic here (if I had it working)
would not permit *removal* of the cron job if it exists. I could put two
logically opposite entries in there to do that, but now it just seems pretty
ugly, so I suspect I'm missing the elegant solution.

Pete

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to