Ask Your Question

exec onlyif script

asked 2016-06-05 22:47:40 -0500

peske gravatar image

I want to accomplish something like:

exec { 'a_name': command => '/path/to/my/', provider => 'shell', onlyif => '/path/to/my/', }

My problem is in onlyif part - I cannot use return in to return true/false. (Or can I?)

If I want to use return in shell, I must create a function, so I've created a function test_fun() which resides in But the next question is how can I call test_fun() from onlyif? First I've tried something like:

onlyif => 'source /path/to/my/; test_fun'

But I've got unknown command source (or something similar). Then I've tried with:

onlyif => '. /path/to/my/; test_fun'

(dot instead of source), and it kinda executes (no error), but what actually happened is that test_fun wasn't been called at all.


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-06-06 14:48:14 -0500

YevgenyT gravatar image

The onlyif parameter can accept only true or false response as condition. You will need to c heck your script exit code instead a function within it.

edit flag offensive delete link more


Thanks for trying to help Yevgeny, but you're wrong (see my answer).

peske gravatar imagepeske ( 2016-06-07 21:20:01 -0500 )edit

answered 2016-06-07 21:23:51 -0500

peske gravatar image

It turned out that it is possible to use shell script in onlyif. You should create the script so that instead of returning true it exit 0 and instead of false use exit 1. The example:

if any_condition; then exit 0 else exit 1 fi

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-06-05 22:47:40 -0500

Seen: 102 times

Last updated: Jun 07 '16