当使用 powershell_script block 时,有没有办法从 chef 登录到控制台。
一个过于简单的例子:
powershell_script "Something Cool" do
ignore_failure true
code <<-EOH
write-host "Hello World"
EOH
end
最佳答案
你想混合 powershell_out,它从 powershell 读取输出的方式与 shell_out 从其他 shell 读取的方式相同。根据客户端 12.4.0 的 Chef 更改日志,powershell_out 现在位于核心 Chef 中 https://github.com/chef/chef/blob/master/CHANGELOG.md
编辑:终于让它在我的环境中工作。请注意,我已锁定综合版本 12.3.0,因此您的体验可能会有所不同。
为了公开 powershell_out,您需要做几件事。
metadata.rb
...
depends 'windows'
<recipe that will be using powershell_out>.rb
...
::Chef::Recipe.send(:include, Chef::Mixin::PowershellOut)
#example usage
should_exist = powershell_out('$true').stdout #=> ['true']
不完全是一个完整的教程,但许多 Bothans 为向您提供这些信息而付出了生命,我希望它是一个有用的起点。哦,执行此方法会引发此警告:
The powershell_out library in the windows cookbook is deprecated.
Please upgrade to Chef 12.4.0 or later where it is built-in to core chef.
所以在 12.4.0+ 中你应该能够直接使用 powershell_out 资源。
关于powershell - Chef PowerShell 日志记录/写入主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32098230/