【发布时间】:2015-02-25 11:32:53
【问题描述】:
Puppet 版本为 3.7,操作系统为 Windows 7。
我正在尝试创建仅在某些 Windows 注册表值不存在时才会执行的 Puppet exec。我正在尝试使用这样的代码:
exec { 'example':
path => 'C:\Windows\System32',
command => 'something',
unless => 'reg query "HKEY_LOCAL_MACHINE\Software\My key" /f 5.1',
}
如果我在命令行上使用reg query,我会得到:
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
因为 result 这个命令是 0 并且unless 应该只在 result 不为 0 时才应该执行这个命令。但是它仍然每次都会执行。
我也尝试过使用unless => 'cmd.exe /C reg query "HKEY_LOCAL_MACHINE\Software\My key" /f 5.1',,但它每次都会执行命令。
这里的类似问题表明这种方式应该可以工作:Exec onlyif registry value is not present。
我在这里做错了什么?
编辑:调试显示 Puppet 根本找不到密钥:
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.
如果我在命令行上运行相同的reg query 命令,它会找到如上所示的密钥。
【问题讨论】:
-
你能从
puppet agent --test --debug的输出中添加一段相关的摘录吗? -
调试提供了新信息。 Puppet 找不到我正在寻找的注册表项,尽管在命令行上执行相同的命令时找到它。
-
这毕竟可能是一个引用问题。我不确定
windows提供者是否会在这里做正确的事情。标记化可能很棘手。
标签: windows command-line registry puppet