exec: How to logoutput => on_failure and get STDERR too?

471 views
Skip to first unread message

Peter Valdemar Mørch

unread,
Feb 14, 2012, 10:05:22 AM2/14/12
to puppet...@googlegroups.com
When a *nix command fails, it most often prints an error to STDERR:

capmon@peter:~> /bin/rm /nonexist
/bin/rm: cannot remove `/nonexist': No such file or directory

exec's logoutput => true doesn't capture STDERR by default:

capmon@peter:~> puppet -e 'exec { e: command => "/bin/rm /nonexist",
logoutput => true }'
err: /Stage[main]//Exec[e]/returns: change from notrun to 0 failed:
/bin/rm /nonexist returned 1 instead of one of [0] at line 1

Instead, it seems one needs to use the shell's redirection for that:

capmon@peter:~> puppet -e 'exec { e: command => "/bin/rm /nonexist
2>&1", logoutput => true }'
notice: /Stage[main]//Exec[e]/returns: /bin/rm: cannot remove
`/nonexist': No such file or directory
err: /Stage[main]//Exec[e]/returns: change from notrun to 0 failed:
/bin/rm /nonexist 2>&1 returned 1 instead of one of [0] at line 1

Is there some way to always include STDERR in logoutput? It seems
brittle, shell dependent, non-portable and redundant to have to put
2>&1 at the end of all exec commands, so I'm hoping there is a better
way...

Peter

Felix Frank

unread,
Feb 21, 2012, 10:35:40 AM2/21/12
to puppet...@googlegroups.com
Hi,

On 02/14/2012 04:05 PM, Peter Valdemar M�rch wrote:
> It seems
> brittle, shell dependent, non-portable and redundant to have to put
> 2>&1 at the end of all exec commands, so I'm hoping there is a better
> way...

while I disagree as far as portability, dependability and savour are
concerned ;-) I agree that it shouldn't be needed.

I suggest you file a bug report and link it here, so that interested
parties can vote on it. Thanks!

Cheers,
Felix

Stefan Schulte

unread,
Feb 22, 2012, 6:13:43 AM2/22/12
to puppet...@googlegroups.com
On Tue, Feb 14, 2012 at 04:05:22PM +0100, Peter Valdemar M�rch wrote:
> When a *nix command fails, it most often prints an error to STDERR:
>
> capmon@peter:~> /bin/rm /nonexist
> /bin/rm: cannot remove `/nonexist': No such file or directory
>
> exec's logoutput => true doesn't capture STDERR by default:
>

What version of puppet are you using? This should have been fixed in
2.6.3 (http://projects.puppetlabs.com/issues/2359)

-Stefan

Reply all
Reply to author
Forward
0 new messages