【发布时间】:2015-08-29 01:21:20
【问题描述】:
在使用 powershell_script 块时,有没有办法从厨师登录到控制台。
一个过于简单的例子:
powershell_script "Something Cool" do
ignore_failure true
code <<-EOH
write-host "Hello World"
EOH
end
【问题讨论】:
标签: powershell chef-infra
在使用 powershell_script 块时,有没有办法从厨师登录到控制台。
一个过于简单的例子:
powershell_script "Something Cool" do
ignore_failure true
code <<-EOH
write-host "Hello World"
EOH
end
【问题讨论】:
标签: powershell chef-infra
您想混合 powershell_out,它从 powershell 读取输出的方式与 shell_out 从其他 shell 读取的方式相同。根据客户端 12.4.0 的主厨更新日志,powershell_out 现在位于核心主厨 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 资源。
【讨论】:
由于 ruby 代码可以编写在说明书中,因此您可以使用“puts”登录到控制台。
【讨论】: