Oh, that makes sense. The require only sets the dependency of cron on exec,
not based on whether the command inside the exec actually happened.

So, is there a way to do what I want to do, which is install the cronjob if
and only if /etc/crontab.txt contains the word "crontab"?

Some context here might be useful ... my text file that I'm checking is
actually an application configuration file, and in some cases the
application and configuration that gets pushed out needs a cron job, and in
others, not.

I suppose I could have the cronjob itself check for the contents:

command => "if grep -q crontab /etc/crontab.txt; then date >> /tmp/date.log;
fi"

but it would be nicer if the cronjob just didn't exist at all.

Pete

On Fri, May 1, 2009 at 1:23 PM, John Florian <[email protected]> wrote:

>
> Pete,
>
> The only thing affected by onlyif here is the /bin/echo command
> itself.  You can even see this in your logged output.
>
> On May 1, 1:56 pm, Pete Emerson <[email protected]> wrote:
> > 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