如果未找到服务,我想执行exec资源,如果找到服务,则跳过exec资源。这是我的尝试:
exec { 'Executing SplunkForwarder Installation Script':
command => 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy remotesigned -file C:\Apps\windows_splunkforwarder_deploy.ps1',
onlyif => if(Get-Service SplunkForwarder) { exit 1 } else { exit 0 },
provider => powershell,
}
如果正确执行了代码,则在找到服务后应跳过exec资源,而在未找到服务时就执行资源。
答案 0 :(得分:0)
您可以查看的一件事是exec中的“ creates”属性。仅当某个文件不存在时,此属性才会触发命令运行。您可能希望代码看起来像这样:
exec { 'Executing SplunkForwarder Installation Script':
command => 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy remotesigned -file C:\Apps\windows_splunkforwarder_deploy.ps1',
creates => 'C:/Program Files/SplunkForwarder',
provider => powershell,
}
如果对exec资源还有其他疑问,可以在此处查看Puppet提供的文档:https://puppet.com/docs/puppet/5.3/types/exec.html#exec-attribute-creates