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+unsubscr...@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.