Ask Your Question
0

Using exec onlyif on Windows properly

asked 2014-11-17 12:38:50 -0500

jabar5459 gravatar image

Hi all, I'm trying to execute a command while waiting for an onlyif flag that will run the exec when the service is not running, but it continues to run it either way.

        exec { 'upgrade Perl Net-HTTP':
            command  => "C:\\Windows\\system32\\cmd.exe ppm upgrade Net-HTTP",
            path     => $::path,
            timeout  => 600,
            provider => windows,
            onlyi    => 'cmd /c "tasklist /FI "IMAGENAME eq service5.exe" /FO "CSV" /NH | findstr.exe "INFO: No tasks"; echo %ERRORLEVEL%',
        }

I'm trying to check that the %ERRORLEVEL% equals 0, when I run the command normally %ERRORLEVEL% is 0 when the service is not running and 1 when the service is running. I've pasted the relevant debug code below, it looks like onlyif is finding a variety of return values but I'm not sure where they are coming from. Anyone have an idea of what I need to change to get Puppet to understand what I'm looking for? I've switched between onlyif and unless to see if was looking at the wrong thing but it appears I get the same result no matter what.

Debug: Exec[upgrade Perl Net-HTTP](provider=windows): Executing check 'cmd /c "tasklist /FI "IMAGENAME eq servuce5.exe" /FO "CSV" /NH | findstr.exe "INFO: No tasks"; echo %ERRORLEVEL%'
Debug: Executing 'cmd /c "tasklist /FI "IMAGENAME eq service5.exe" /FO "CSV" /NH | findstr.exe "INFO: No tasks"; echo %ERRORLEVEL%'
Debug: /Stage[main]/Tmp/Exec[upgrade Perl Net-HTTP]/onlyif: "service5.exe","3328","RDP-Tcp#0","2","15,572 K"
Debug: Exec[upgrade Perl Net-HTTP](provider=windows): Executing 'C:\Windows\system32\cmd.exe ppm upgrade Net-HTTP'
Debug: Executing 'C:\Windows\system32\cmd.exe ppm upgrade Net-HTTP'
Notice: /Stage[main]/Tmp/Exec[upgrade Perl Net-HTTP]/returns: executed successfully
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-11-17 16:14:35 -0500

updated 2014-11-17 16:16:15 -0500

onlyif should evaluate to not zero if you want the exec to happen.

You should also probably pipe the output for the echo instead of using a semi-colon.

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

Stats

Asked: 2014-11-17 12:38:50 -0500

Seen: 1,322 times

Last updated: Nov 17 '14