Actually you can emulate what you want if you join the commands with &&.
Something like the following:

$command = "/bin/ls /doesnotexit; /bin/echo hello"

exec { 'cool':
    command => join(split($command, '; '), " && "),
}

Note1: you will need https://github.com/puppetlabs/puppetlabs-stdlib for
this. Although I suppose you already have it.

Note2: this is not tested but it should work. Of course it written
in a generic way so you can wrap it in a define let's say.

Note3: the error messages from this can be cryptic...

P.S. Hate using execs..

-- 
Nikola


On Mon, Mar 10, 2014 at 12:57:13PM -0700, David Portabella wrote:
> I don't agree with this statement.
> in bash, for example, if you type "set -e" first, bash will stop and fail 
> as soon as a concatenated command fails.
> (i agree that this behaviour is unfortunatelly not enabled by default in 
> bash scripts)
> 
> > If you need to control each of the return codes just use different exec 
> resources
> 
> > If "you",
> the problem is that there are many puppet modules which use concatenated 
> commands, without realising about this problem.
> to be safe, I am suggesting that puppet should enable that behavior by 
> default.
> 
> > need to control each of the return codes
> i don't suggest executing every concatenated command and control each 
> return control.
> i am suggesting failing as soon as a concatenated command fails. (as in 
> bash set -e)
> > just use different exec resources
> as a side note, 
> another improvement about puppet exec would be that the exec command can be 
> an array of strings, executed in order as long as none fails.
> 
> 
> Regards,
> David
> 
> 
> On Monday, March 10, 2014 6:46:32 PM UTC+1, Jose Luis Ledesma wrote:
> >
> > When you use concatenated commands any shell will only return the last 
> > command return code by design, and this is what puppet receives. So its a ' 
> > works at a expected'
> >
> > If you need to control each of the return codes just use different exec 
> > resources
> >
> > Regards,
> > El 10/03/2014 16:02, "David Portabella" 
> > <[email protected]<javascript:>> 
> > escribió:
> >
> >>
> >> exec {'test':
> >>   command => "/bin/ls /doesnotexit", 
> >> }
> >>
> >> fails as expected:
> >>
> >> Error: /bin/ls /doesnotexit returned 1 instead of one of [0]
> >> Error: /Stage[main]//Exec[test]/returns: change from notrun to 0 failed: 
> >> /bin/ls /doesnotexit returned 1 instead of one of [0]
> >>
> >> However, 
> >> exec {'test':
> >>   command => "/bin/ls /doesnotexit; /bin/echo hello", 
> >> }
> >>
> >> does not fail, because the last command did not return an error!
> >>
> >> that's a problem, because there are many puppet modules which concatenate 
> >> several commands in one puppet exec, and they do not explicitly handle the 
> >> errors.
> >>
> >> (inserting "set -e" at the head of the command line does not work, as it 
> >> is bash script specific)
> >>
> >> *I think that, by default, the puppet exec resource should fail if any of 
> >> the "single commands" fail (as *
> >> *in the second example). and if it is not by default, at least there 
> >> should be an option in puppet exec to do so (equivalent to "set -e" in 
> >> bash)*
> >>
> >> (tested on puppet 3.3.2)
> >>
> >>
> >>  -- 
> >> 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 [email protected] <javascript:>.
> >> To view this discussion on the web visit 
> >> https://groups.google.com/d/msgid/puppet-users/fc8a32ca-1e7b-4376-ace7-a1c36dd665c3%40googlegroups.com<https://groups.google.com/d/msgid/puppet-users/fc8a32ca-1e7b-4376-ace7-a1c36dd665c3%40googlegroups.com?utm_medium=email&utm_source=footer>
> >> .
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> >
> 
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/73dbd33c-4d80-4631-97b9-b860eddc5f37%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/20140311095614.GC934%40nikolavp-desktop.
For more options, visit https://groups.google.com/d/optout.

Reply via email to