Puppet不在Windows 2008服务器上运行PowerShell脚本

我的Windows虚拟机上的Puppet代理没有执行PowerShell脚本。 我用一个非常简单的脚本来testing它。 该脚本作为test.ps1存储在C驱动器上。 其内容如下:

"$(Get-Date -format F)" | Out-File C:\z.txt -Encoding ASCII 

当我手动从PowerShell控制台运行./test.ps1时,它工作正常,文件z.txt被创build。 但由于某种原因,伪装代理不运行这个。 我的site.pp的内容是:

 exec { "Run Script": command => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Executionpolicy Unrestricted -File c:/test.ps1', logoutput => true, refreshonly => true, } 

而虚拟机本身的“puppet agent -t”的输出是:

 C:\Users\Administrator>puppet agent -t Info: Retrieving pluginfacts Warning: Copying owner/mode/group from the source file on Windows is deprecated; use source_permissions => ignore. (at C:/Program Files (x86)/Puppet Labs/Puppet/puppet/lib/puppet/type/file/sou rce.rb:120:in `each') Info: Retrieving plugin Info: Caching catalog for f9881998-7fdf-4e96-a784-d9690fcd5495 Info: Applying configuration version '1410182959' Notice: Finished catalog run in 0.42 seconds 

所以在我看来,任何地方都没有错误,但是PowerShell脚本仍然不能运行。 我究竟做错了什么?

exectypes的Puppet资源不会自动同步。 它只是“刷新”自己,这意味着只有当资源收到来自另一个资源的信号,这个资源成功地从非同步状态改变时,该命令才被运行。

 file { 'C:\not-yet-existent': ensure => 'file', notify => Exec['Run Script'], } 

这不是一个很好的操作模式,因为如果你的脚本因为某种原因失败了,Puppet可能不会知道创build一个新的事件,因为现在的file资源是同步的。

最好不要使用refreshonly => true ,而要给木偶一个提示,以便找出是否运行命令。 exectypes可以通过它onlyifunless 参数 ,而且通常有用的(如你的情况) creates参数。

 exec { "Run Script": command => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Executionpolicy Unrestricted -File c:/test.ps1', logoutput => true, creates => 'C:\z.txt', }