Hi all, if I define a file resource without specifying an ensure parameter, it seems to behave like ensure => present was specified. I''m trying to require a file only when a command is executed, using something like this: file{''myfile'': path => ''/tmp/myfile'', source => "puppet:///modules/myexample/myfile", } exec { "myexec": command => "/usr/local/bin/do_something -f /tmp/myfile", onlyif => "/usr/local/bin/mytest", require => [ File["myfile"], ]; } but it always creates myfile, regardless to mytest. Is there a way to bind the creation to the onlyif test? Thanks -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, April 4, 2013 5:44:40 AM UTC-5, carlo montanari wrote:> > Hi all, > > if I define a file resource without specifying an ensure parameter, it > seems to behave like ensure => present was specified. >Yes, that''s the default.> I''m trying to require a file only when a command is executed, using > something like this: > > file{''myfile'': > path => ''/tmp/myfile'', > source => "puppet:///modules/myexample/myfile", > } > > exec { "myexec": > command => "/usr/local/bin/do_something -f /tmp/myfile", > onlyif => "/usr/local/bin/mytest", > require => [ > File["myfile"], > ]; > } > > but it always creates myfile, regardless to mytest. >Yes, it''s a managed file. The require just directs Puppet to apply it before attempting to apply the Exec. Is there a way to bind the creation to the onlyif test?> >It depends. Puppet will not apply one resource in the middle of applying a different one. Specifically, it will not under any circumstances apply a File between evaluating the Exec''s ''onlyif'' test and running its command. If the file can be applied conditionally on success of the whole Exec then just making the File ''require'' the Exec should do the trick. There''s an important caveat here, however: the overall Exec succeeds (without running the command) when the onlyif test fails, so that probably doesn''t achieve what you want. The best you can do might be to turn the onlyif test into a custom fact. That will cause it to run much earlier (before any resources are applied), and it will make the result available in your manifests, so that you can declare both the File and Exec only if the test succeeded. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Hi, On 04/04/2013 05:08 PM, jcbollinger wrote:> if I define a file resource without specifying an ensure parameter, > it seems to behave like ensure => present was specified. > > > > Yes, that''s the default.Uhm, are you sure? I would expect the following to be a noop, which seems to be the case: $ puppet apply -e ''file { "/tmp/wth": mode => 640 }'' notice: Finished catalog run in 0.05 seconds Puppet *will* change the file mode, if it''s not 640, but will not mess with the resource''s existence. A different behavior would be confusing, to me at least. Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Perhaps it works differently when specifying the content/source of a file. I tried your example, but with content => ''foo'' instead of mode => 640 and it created the file. On Sunday, April 14, 2013 8:55:07 AM UTC-7, Felix.Frank wrote:> > Hi, > > On 04/04/2013 05:08 PM, jcbollinger wrote: > > if I define a file resource without specifying an ensure parameter, > > it seems to behave like ensure => present was specified. > > > > > > > > Yes, that''s the default. > > Uhm, are you sure? I would expect the following to be a noop, which > seems to be the case: > > $ puppet apply -e ''file { "/tmp/wth": mode => 640 }'' > notice: Finished catalog run in 0.05 seconds > > Puppet *will* change the file mode, if it''s not 640, but will not mess > with the resource''s existence. > > A different behavior would be confusing, to me at least. > > Cheers, > Felix >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On 04/15/2013 09:31 AM, Ellison Marks wrote:> Perhaps it works differently when specifying the content/source of a > file. I tried your example, but with content => ''foo'' instead of mode => > 640 and it created the file.Yes, I believe that''s an important distinction. One would expect ''content =>'' to imply ''ensure => file'', and ''source =>'' to imply file if the source is indeed a file, or directory if the source is a directory as well. Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On Sunday, April 14, 2013 10:55:07 AM UTC-5, Felix.Frank wrote:> > Hi, > > On 04/04/2013 05:08 PM, jcbollinger wrote: > > if I define a file resource without specifying an ensure parameter, > > it seems to behave like ensure => present was specified. > > > > > > > > Yes, that''s the default. > > Uhm, are you sure? I would expect the following to be a noop, which > seems to be the case: > >Ah, my bad. Most ''ensure'' properties do default to ''present'' (https://github.com/puppetlabs/puppet/blob/master/lib/puppet/property/ensure.rb), but the File resource''s is a special case, with no default value (https://github.com/puppetlabs/puppet/blob/master/lib/puppet/type/file/ensure.rb). When file content is specified, however, whether via the ''content'' property or the ''source'' property, syncing the resource involves ensuring the file is present and has the specified content. Thus, use of either of those properties effectively implies something similar to "ensure => ''file''". John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On Monday, April 15, 2013 9:40:36 AM UTC-5, jcbollinger wrote:> > Thus, use of either of those properties effectively implies something > similar to "ensure => ''file''". > >I''m not inclined at the moment to verify what happens if ''ensure'' is unspecified and ''source'' points to a directory. I agree, however, that for consistency it ought to cause the target path to be a directory. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.