[Puppet Users] Re: using return value of a shell command as a puppet conditional

cyrus
Mon, 31 Jan 2011 22:06:13 -0000

If I understand your question you want to use the exec resource and
specify the onlyif (or unless) parameter.

Sort of like:

exec {
    "cp /tmp/file1 /data",
    path => [ "/bin" ],
    onlyif => "/usr/bin/my_harmless_binary";
}

On Jan 31, 2:12 pm, Ashley Gould <ago...@ucop.edu>
wrote:
> Hi all,
>
> My first post.  I am just getting started with puppet and have made
> good progress with some basics using templates and files.
>
> I would like to perform and an action based on whether or not a
> particular system binary executes successfully, but I don''t see an
> obvious way to set puppet conditionals based on an exit value of an
> arbitrary command.  Is there a well known recipe that does something
> like this shell snippet?:
>
> if [ "/usr/bin/my_harmless_binary 2>&1 >/dev/null" ];
then
>   echo "my_harmless_binary succeeded"
>   cp /tmp/file1 /data/
> else
>   echo "my_harmless_binary FAILED"
> fi
>
> --
>
> -ashley
>
> Did you try poking at it with a stick?