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 puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
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 <pemer...@gmail.com> 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 puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
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 <john.florian@dart.biz> 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 <pemer...@gmail.com> 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 puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Ah I see a new thread, "Assign variable with content of a file?" that lines up with my needs, I''ll check out the suggestions there. Pete On Sat, May 2, 2009 at 7:22 AM, Pete Emerson <pemerson@gmail.com> wrote:> 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 <john.florian@dart.biz>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 <pemer...@gmail.com> 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 puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
On May 2, 10:29 am, Pete Emerson <pemer...@gmail.com> wrote:> Ah I see a new thread, "Assign variable with content of a file?" that lines > up with my needs, I''ll check out the suggestions there.Yeah, it''s mine! I found yours when I was looking for my own solution -- it sounds like we''re both trying to achieve something rather similar. :-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---