Puppet version is 3.7 and OS is Windows 7.
I am trying to create Puppet exec that would only execute if certain Windows registry value does not exist. I am trying to use code like this:
exec { 'example':
path => 'C:\Windows\System32',
command => 'something',
unless => 'reg query "HKEY_LOCAL_MACHINE\Software\My key" /f 5.1',
}
If I use reg query
on command line I get:
C:\>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\My key" /f 5.1
HKEY_LOCAL_MACHINE\SOFTWARE\My key REG_SZ 5.1
End of search: 1 match(es) found.
C:\>echo %errorlevel%
0
Since result this command is 0 and unless
should execute only if result is not 0 the command should not execute. However it still gets executed every time.
I also tried using unless => 'cmd.exe /C reg query "HKEY_LOCAL_MACHINE\Software\My key" /f 5.1',
but it executes the command every time as well.
Similar question here indicates that this way should work: Exec onlyif registry value is not present.
What am I doing wrong here?
EDIT: Debug shows that Puppet does not find the key at all:
Debug: Exec[update](provider=windows): Executing check 'reg query "HKLM\SOFTWARE\My key" /f 5.1'
Debug: Executing 'reg query "HKLM\SOFTWARE\My key" /f 5.1'
Debug: /Stage[main]/Example/Exec[update]/unless: ERROR: The system was unable to find the specified registry key or value.
If I run the same reg query
command on the command line it finds the key as shown above.