powershell - Chef PowerShell 日志记录/写入主机

标签 powershell chef-infra

当使用 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/

相关文章:

powershell - AD 组比较 - PowerShell

powershell - SSRS 和 PowerShell : Get report as Excel

c# - 我可以从 PowerShell 访问我的自定义 .NET 类吗?

vagrant - Chef : No such cookbook

c# - 手工制作的 Chef API 请求 - 获取 "invalid signature for user"

ruby-on-rails - 如何在 Vagrant 中获取 IP 地址?

chef-infra - 有什么方法可以从 Chef 服务器生成并获取验证 key 吗?

mysql - 通过PowerShell远程连接连接到MySQL

powershell - 使用 Powershell DSC 在环境中管理多台服务器

ruby - 如何更改 Vagrant (VDD) VM 的 php 和 xdebug 版本?