exec onlyif not working on windows

asked 2018-07-12 08:06:51 -0500

daniel.serrao gravatar image


I'm trying to make sure that a Splunk Forwarder instance is always running, but I don't want to execute the command to start Splunk every time that Puppet runs, so I'm using the following resource:

exec {'Start Splunk':
  command => 'splunk start',
  path    => 'C:/SplunkUniversalForwarder/bin',
  onlyif  => 'splunk.exe status | findstr /i "Stopped"',
  require => Exec['Install splunk forwarder'],

In the windows cmd, if I execute the command splunk.exe status | findstr /i "Stopped" I get SplunkForwarder: Stopped. Then if I execute echo Exit Code is %errorlevel% I get Exit Code is 0.

According to the documentation, the command 'splunk start' in the exec should be executed when the command inside the onlyif return exit code 0, but in this case is never executed. I'm assuming this problem or difference is related to Windows since I never had problems in using the onlyif on Linux.

Anyone knows how to solve this?

I'm using Puppet 5.5 and Windows Server 2012 R2.

Thanks for any help.

edit retag flag offensive close merge delete