简体   繁体   English

Chef PowerShell Logging / Write-Host

[英]Chef PowerShell Logging/Write-Host

Is there a way to log to the console from chef when using a powershell_script block. 有没有办法在使用powershell_script块时从chef登录到控制台。

An oversimplified example: 一个简单的例子:

powershell_script "Something Cool" do
  ignore_failure true
  code <<-EOH
    write-host "Hello World"
  EOH
end

You want to mixin powershell_out, which reads output from the powershell in the same way shell_out reads from other shells. 你想混合powershell_out,它从powershell读取输出,就像shell_out从其他shell读取的一样。 According to the chef changelog as of client 12.4.0 powershell_out now lives in core chef https://github.com/chef/chef/blob/master/CHANGELOG.md 根据客户12.4.0的主厨更新日志,powershell_out现在住在核心厨师https://github.com/chef/chef/blob/master/CHANGELOG.md

EDIT: Finally got this to work in my environment. 编辑:最后让这个在我的环境中工作。 Bare in mind, I'm locked to omnibus version 12.3.0 so your experience may differ. 请记住,我已经锁定了omnibus版本12.3.0,因此您的体验可能会有所不同。

In order to expose powershell_out you need to do a couple things. 为了公开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']

Not exactly a full tutorial but many Bothans died to bring you this information and I hope it's a useful jumping off point. 不完全是一个完整的教程,但许多Bothans为你带来了这些信息,我希望这是一个有用的跳跃点。 Oh, and doing this method throws this warning: 哦,做这个方法会抛出这个警告:

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.

so in 12.4.0+ you should be able to use the powershell_out resource directly. 所以在12.4.0+中你应该能够直接使用powershell_out资源。

由于ruby代码可以写在cookbook中,你可以使用“puts”来登录控制台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM