jimbob palmer
2012-Feb-17 15:12 UTC
[Puppet Users] Puppet unless behaviour with a dependency
Is this really expected behaviour? Should the second Exec succeed even if the first never runs? exec { "one": command => "/bin/true", unless => ''/bin/false'' } exec { "two": command => "/bin/true", require => Exec["one"], } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/xXTAEUbdEncJ. 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.
jimbob palmer
2012-Feb-17 15:15 UTC
[Puppet Users] Re: Puppet unless behaviour with a dependency
Sorry: exec { "one": command => "/bin/true", unless => ''/bin/true'' } exec { "two": command => "/bin/true", require => Exec["one"], } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/5bb-NN8Pu5sJ. 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.
R.I.Pienaar
2012-Feb-17 15:19 UTC
Re: [Puppet Users] Puppet unless behaviour with a dependency
----- Original Message -----> From: "jimbob palmer" <jimbobpalmer@gmail.com> > To: puppet-users@googlegroups.com > Sent: Friday, February 17, 2012 3:12:46 PM > Subject: [Puppet Users] Puppet unless behaviour with a dependency > > Is this really expected behaviour? Should the second Exec succeed > even if the first never runs? > > exec { "one": > command => "/bin/true", > unless => ''/bin/false'' > } > exec { "two": > command => "/bin/true", > require => Exec["one"], > }I think this is https://projects.puppetlabs.com/issues/5876 i think this is a major failure of Puppet to honour what people expect and what the language suggests in the choice of meta param names etc but there''s some debate in that ticket -- 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.
jimbob palmer
2012-Feb-17 15:41 UTC
[Puppet Users] Re: Puppet unless behaviour with a dependency
On Feb 17, 4:19 pm, "R.I.Pienaar" <r...@devco.net> wrote:> ----- Original Message ----- > > From: "jimbob palmer" <jimbobpal...@gmail.com> > > To: puppet-users@googlegroups.com > > Sent: Friday, February 17, 2012 3:12:46 PM > > Subject: [Puppet Users] Puppet unless behaviour with a dependency > > > Is this really expected behaviour? Should the second Exec succeed > > even if the first never runs? > > > exec { "one": > > command => "/bin/true", > > unless => ''/bin/false'' > > } > > exec { "two": > > command => "/bin/true", > > require => Exec["one"], > > } > > I think this ishttps://projects.puppetlabs.com/issues/5876 > > i think this is a major failure of Puppet to honour what people expect > and what the language suggests in the choice of meta param names etc > but there''s some debate in that ticketIt''s causing me a real headache. I need to run an expensive command if a string is not present in a file. If the string is present, I abort. That expensive command finishes by writing the string to the file. If the expensive command runs I need to run a second command, which is also expensive to run. How can I do this? If I duplicate the unless the second command can never run since the string will be present in the file. -- 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.
jimbob palmer
2012-Feb-17 16:01 UTC
[Puppet Users] Re: Puppet unless behaviour with a dependency
On Feb 17, 4:41 pm, jimbob palmer <jimbobpal...@gmail.com> wrote:> On Feb 17, 4:19 pm, "R.I.Pienaar" <r...@devco.net> wrote: > > > > > > > > > > > ----- Original Message ----- > > > From: "jimbob palmer" <jimbobpal...@gmail.com> > > > To: puppet-users@googlegroups.com > > > Sent: Friday, February 17, 2012 3:12:46 PM > > > Subject: [Puppet Users] Puppet unless behaviour with a dependency > > > > Is this really expected behaviour? Should the second Exec succeed > > > even if the first never runs? > > > > exec { "one": > > > command => "/bin/true", > > > unless => ''/bin/false'' > > > } > > > exec { "two": > > > command => "/bin/true", > > > require => Exec["one"], > > > } > > > I think this ishttps://projects.puppetlabs.com/issues/5876 > > > i think this is a major failure of Puppet to honour what people expect > > and what the language suggests in the choice of meta param names etc > > but there''s some debate in that ticket > > It''s causing me a real headache. > > I need to run an expensive command if a string is not present in a > file. If the string is present, I abort. That expensive command > finishes by writing the string to the file. > > If the expensive command runs I need to run a second command, which is > also expensive to run. > > How can I do this? If I duplicate the unless the second command can > never run since the string will be present in the file.This also doesn''t work :( command => "/bin/true; /bin/second_command" -- 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.
Adam Heinz
2012-Feb-17 16:12 UTC
Re: [Puppet Users] Re: Puppet unless behaviour with a dependency
Something like this? exec { "second command": refreshonly => true, subscribe => Exec["first command"], } -- 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.
jimbob palmer
2012-Feb-17 16:22 UTC
[Puppet Users] Re: Puppet unless behaviour with a dependency
On Feb 17, 5:12 pm, Adam Heinz <a...@metricwise.net> wrote:> Something like this? > > exec { "second command": > refreshonly => true, > subscribe => Exec["first command"], > > > > > > > > }Gah! I''m five minutes behind you. It works - THANKS. -- 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.
jcbollinger
2012-Feb-17 22:03 UTC
[Puppet Users] Re: Puppet unless behaviour with a dependency
On Feb 17, 9:19 am, "R.I.Pienaar" <r...@devco.net> wrote:> ----- Original Message ----- > > From: "jimbob palmer" <jimbobpal...@gmail.com> > > To: puppet-users@googlegroups.com > > Sent: Friday, February 17, 2012 3:12:46 PM > > Subject: [Puppet Users] Puppet unless behaviour with a dependency > > > Is this really expected behaviour? Should the second Exec succeed > > even if the first never runs? > > > exec { "one": > > command => "/bin/true", > > unless => ''/bin/false'' > > } > > exec { "two": > > command => "/bin/true", > > require => Exec["one"], > > } > > I think this ishttps://projects.puppetlabs.com/issues/5876No, I don''t think this is 5876. That involves an Exec that ''require''s a *failing* resource, but which runs anyway because it also ''subscribe''s to resources that are applied successfully. This case is quite different: Exec[''two''] depends on a resource that *succeeds*, therefore there is no reason why it should not run. The key point here is that the ''unless'' and ''onlyif'' parameters of an Exec never themselves cause that Exec to fail. Instead, they are among an Exec''s ways of determining whether it is already in sync, and a resource that is already in sync succeeds trivially. If the Exec is not already in sync then its command is run, and its success is judged by the return value.> i think this is a major failure of Puppet to honour what people expect > and what the language suggests in the choice of meta param names etc > but there''s some debate in that ticketI think 5876 is a real problem, but not so much the issue presented here. People can evidently be taken by surprise, but I rate that a documentation issue. The behavior itself is sensible and desirable. Moreover, the alternative is already available by putting the condition into the command, like so: exec { ''example'': command => ''/usr/bin/ fail_when_the_command_shouldnt_run && /usr/bin/the_command'' } As the OP discovered, the alternative can also be achieved via subscribe / notify. John -- 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.
jimbob palmer
2012-Feb-20 10:39 UTC
[Puppet Users] Re: Puppet unless behaviour with a dependency
On Feb 17, 5:22 pm, jimbob palmer <jimbobpal...@gmail.com> wrote:> On Feb 17, 5:12 pm, Adam Heinz <a...@metricwise.net> wrote: > > > Something like this? > > > exec { "second command": > > refreshonly => true, > > subscribe => Exec["first command"], > > > } > > Gah! I''m five minutes behind you. It works - THANKS.The problem that this creates is that *any* update now runs the command from the subscribe, which isn''t ideal, but I guess will work for now :) -- 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.
jcbollinger
2012-Feb-20 15:03 UTC
[Puppet Users] Re: Puppet unless behaviour with a dependency
On Feb 20, 4:39 am, jimbob palmer <jimbobpal...@gmail.com> wrote:> On Feb 17, 5:22 pm, jimbob palmer <jimbobpal...@gmail.com> wrote: > > > On Feb 17, 5:12 pm, Adam Heinz <a...@metricwise.net> wrote: > > > > Something like this? > > > > exec { "second command": > > > refreshonly => true, > > > subscribe => Exec["first command"], > > > > } > > > Gah! I''m five minutes behind you. It works - THANKS. > > The problem that this creates is that *any* update now runs the > command from the subscribe, which isn''t ideal, but I guess will work > for now :)I don''t follow. Do you mean that if any resource at all on the target node is updated by Puppet, then the second Exec runs? That should not be. An Exec marked with "refreshonly => true" should only run if it receives a signal. Or do you mean that the *first* command is executing on every Puppet run? That''s not influenced by the DSL fragment you quoted. Here''s a complete example that should work: ===class test::manage_my_file { $my_file = ''/tmp/test'' $target_string = ''So long, and thanks for all the fish'' file { "${my_file}": ensure => ''file'' } exec { ''command_one'': command => "echo ''${target_string}'' >> ${my_file}", unless => "grep -q ''${target_string}'' ${my_file}", require => File["${my_file}"] } exec { ''command_two'': command => "/bin/cp ${my_file} /tmp/test2", refreshonly => true, subscribe => Exec[ ''command_one'' ] } } node default { include ''test::manage_my_file'' } === With that as your site.pp (to exclude any possibility of influence by other manifest files), you should see Exec[''command_one''] run unless the string "So long, and thanks for all the fish" is present in file / tmp/test on the target node (any target node). If Exec[''command_one''] runs then Exec[''command_two''] should run after. If Exec[''command_one''] *does not* run, then neither should Exec[''command_two'']. If Exec[''command_one''] runs when /tmp/test already contains the target string, or if Exec[''command_two''] runs when Exec[''command_one''] did not first run in the same session, then you should file a bug report. If this approach does not appear to work when you adapt it to your problem, then do check at least these things: 1) that your ''unless'' command is exiting with the expected return code. If it always returns a false (non-zero) exit code then the two execs will always run. 2) that no other resource is set to ''notify'' Exec[''command_two'']. If you use resource defaults anywhere in your configuration then don''t forget to check those, too. Also, beware of any resource notifying a collection of Execs, as such a collection could easily include Exec[''command_two''] without explicitly naming it. John -- 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.