Problems with "onlyif" in Exec

62 views
Skip to first unread message

Jan-Frederic Markert

unread,
Jan 20, 2014, 6:39:02 AM1/20/14
to puppet...@googlegroups.com
Hey,

we want to check a condition before executing some commands.
If a line is existing in a list of architectures, the command should not run - and vice versa.
So we use grep and count the words (wc -l).

The expected behaviour: if the onlyif-command returns 0, execute. If not, don't.

Running the onlyif-command separately from puppet exectution, the return value is as expected.
But the Exec-command is executed every time, despite the actual return value.
Also, running "echo 0" as well as "echo 1" as onlyif triggers an execution.

Here is the code snippet used in our manifest

exec { "hammer execution":
        command => "hammer architecture create --name x86_64 \
                && hammer environment create --name cloudbox",
        path    => "/usr/local/bin/",
        require => [
                        File["/var/log/foreman/hammer.log"],
                        File["/etc/foreman/cli_config.yml"],
                        Package["hammer_cli_foreman"],
                ],
       # onlyif  => "hammer architecture list | /bin/grep 'x86_64' | /usr/bin/wc -l",
        onlyif => "/bin/echo 1",
        user    => ccka,
        environment     => ["HOME=/home/ccka"],
}

Does anyone have an idea what's going wrong?

Regards,
Fredi

Andrey Kozichev

unread,
Jan 20, 2014, 8:10:08 AM1/20/14
to puppet...@googlegroups.com

Onliif looks at exit code, not at echo value.

If you are piping - it will be exit code of the last command.

Use grep -q or something to get a non-zero code

--
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 puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/b44c8522-14e2-48a0-9459-7a2a6b0c3721%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages