Eric Sorenson
2010-Apr-23 22:47 UTC
[Puppet Users] read-only ''ensure'' for File resource?
rlpowell mentioned this earlier on irc and i find myself in a similar boat - I need to express a condition that doesn''t fit neatly into the class/parameter model and I''m not quite sure how to do it. i''d like to add a cron entry IFF a particular file (not managed through puppet) exists. Seems like the natural thing would be to do: cron { "myjob": command => "/run/this/script.sh", user => roleacct, minute => [0,30], require => File["/run/this/script.sh"] } file { "/run/this/script.sh": ensure => XXX } where XXX is some value that would not cause any changes to the file but merely mark the resource as passing or failing depending on the stat(). Exec''ing /bin/test is possible but I kind of hate execs. I''m not super happy about having a resource intentionally fail but I''m not sure what else to do about it. Any thoughts from others on how to accomplish this? -=Eric -- 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.
Jesús M. Navarro
2010-Apr-24 11:13 UTC
Re: [Puppet Users] read-only ''ensure'' for File resource?
Hi, Eric: On Saturday 24 April 2010 00:47:20 Eric Sorenson wrote:> rlpowell mentioned this earlier on irc and i find myself in a similar boat > - I need to express a condition that doesn''t fit neatly into the > class/parameter model and I''m not quite sure how to do it. i''d like to add > a cron entry IFF a particular file (not managed through puppet) exists. > Seems like the natural thing would be to do: > > cron { "myjob": > command => "/run/this/script.sh", > user => roleacct, > minute => [0,30], > require => File["/run/this/script.sh"] > } > > file { "/run/this/script.sh": > ensure => XXX > } > > where XXX is some value that would not cause any changes to the file but > merely mark the resource as passing or failing depending on the stat().Since the job execution depends on a resource not already managed by puppet, why you don''t delegate the decision to the cron job itself? I mean, make sure the cron job is always present and then let it test for the file as in: if [ -x /run/this/script.sh ]; then /run/this/script.sh fi Cheers. -- 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.
Thomas Bellman
2010-Apr-24 11:20 UTC
Re: [Puppet Users] read-only ''ensure'' for File resource?
On 04/24/10 00:47, Eric Sorenson wrote:> rlpowell mentioned this earlier on irc and i find myself in a similar > boat - I need to express a condition that doesn''t fit neatly into the > class/parameter model and I''m not quite sure how to do it. i''d like > to add a cron entry IFF a particular file (not managed through puppet) > exists.Someone else just posted an alternative way to solve it, which works well for cron jobs, where you let the cron job itself check if the script exists. For the more general problem, though, a custom fact is the proper way to do that. Something like: Facter.add(''run_this_script_exists'') do setcode do File.exist?("/run/this/script.sh") ? "true" : "" end end And then use it like this: if $run_this_script_exists { cron { "myjob": ... } } There are some plans to add ''onlyif'' and ''unless'' as metaparameters that would work on all resource types. (Today those ''onlyif'' and ''unless'' only exists for the ''exec'' type.) However, for now custom facts is the only way to do it. /Bellman -- 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.