Ask Your Question

onlyif ignored in exec

asked 2017-09-06 05:42:53 -0600

nextshellid gravatar image

updated 2017-09-07 03:29:22 -0600

Hello Why onlyif has no effect here ? it will run the command anyway.

exec { 'splunk_app_unix_linux':
  command => "splunk install app ${opspk_repo_source}/${opspk_app_unix} -auth admin:${opspk_admin_pass}",
  user    => 'splunk',
  creates => '/opt/splunk/etc/apps/splunk_app_for_nix/app.manifest',
  onlyif  => [ '! service splunk status' ,],
  notify  => Service['splunk'],
  path    => ['/bin', '/usr/bin', '/sbin', '/usr/sbin', '/usr/loca/bin', '/opt/splunk/bin/',],
  provider => 'shell',


I'm already using a Splunk module and I've got to do things that way due to circle dependencies and I'm not experienced enough to get out of them. The command will add an "in-app splunk application" but the service must be running before the command can run hence "onlyif". By the way, I've tried different bash statements and without any expected result.

It's very strange, it's like onlyif attribute is ignored altogether, could there be a collision between attributes ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-09-08 17:21:15 -0600

nextshellid gravatar image

The problem was that command "service status splunk", while executed by puppet it probably returns none, I've replaced with "splunk status", obviously have the "/opt/spunk/bin/" in your path!

edit flag offensive delete link more

answered 2017-09-06 09:29:19 -0600

DarylW gravatar image

updated 2017-09-07 08:20:12 -0600

Are you saying that it will still run the command even if the service is stopped? or are you trying to get it to not rerun the command while the service is running, but it is already added? That would require some more complicated unless/onlyif logic.

A few comments.
Have you looked into any of the existing splunk modules on the forge? There is one that is maintained by voxpupli ( )

If you wish to use the 'not' condition for a command, you should use the unless parameter ( Documentation )

You can debug how unless/onlyif interacts with commands. You can always put in /bin/true or /bin/false as the commands for onlyif or unless to debug it, and you could put 'echo' statements as your commands, to just play around and figure out how it works.

UPDATE: Oh, you are using both 'creates' and 'onlyif'... I don't believe that they mix, it typically applies one or the other... You can experiment with a simple combination of the statements to see how it behaves, I don't have a system right now to verify that for you.

edit flag offensive delete link more


Yes, it does not matter whether the service is stopped or started the command will run anyway, also with or without the exclamation point ! I'll add the rest of the info into the initial question.

nextshellid gravatar imagenextshellid ( 2017-09-07 03:24:34 -0600 )edit

If you are running it trouble using the splunk module, feel free to ask a question in the #voxpupuli channel on freenode IRC, or open an issue on the repository, they are usually pretty happy to help people work through problems

DarylW gravatar imageDarylW ( 2017-09-07 08:21:21 -0600 )edit

You may also be better served combining the logic into a single statement. onlyif and unless can take arrays, but You would have to play with them to see if they behave how you expect (setting up a truth table with all the combinations of onlyif/unless => ['/bin/true', '/bin/false']

DarylW gravatar imageDarylW ( 2017-09-08 09:46:40 -0600 )edit

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: 2017-09-06 05:42:53 -0600

Seen: 874 times

Last updated: Sep 08 '17