sh - How do I ensure a Puppet exec resource always includes `set -o pipefail`? -


in particular project, have lot of puppet exec resources pipes. seems work fine.

exec { 'foobar':    command => 'foo | bar', } 

however, there occasions foo fails. default behavior report exit code last command in pipeline. can fix manually.

exec { 'foobar':    command  => 'set -o pipefail; foo | bar',   provider => shell, } 

but, want make sure happens in these cases automatically. i'd avoid manual find/replace , auditing uses of exec.

  • am missing useful attribute?
  • is there wrapper can use?
  • am i, unfortunately, looking @ custom resource?

  • am missing useful attribute?

no, exec has no attribute automatically prepend additional code command.

  • is there wrapper can use?

i'm not confident understand mean "wrapper", see below.

  • am i, unfortunately, looking @ custom resource?

if you're asking whether need implement native custom type, surely not. can undoubtedly address problem (dsl-level) defined type, though need adjust exec declarations declarations of defined type instead. may mean "wrapper" -- i'm sure there's no existing 1 particular purpose, shouldn't hard create one:

define mymodule::exec (   command     => $title,   creates     => 'not set',   cwd         => 'not set',   # ... other regular parameters ... ) {   $real_provider = $provider ? { 'not set' => 'shell', default => $provider }   if $real_provider == 'shell' {     $real_command = "set -o pipefail; $command"   } else {     warning('non-shell command declared via mymodule::exec')     $real_command = $command   }    exec { $title:     command  => $real_command,     provider => $real_provider,     creates  => $creates ? { 'not set' => undef, default => $creates },     cwd      => $cwd ? { 'not set' => undef, default => $cwd },     # ... remaining regular parameters ...   } } 

Comments