Chef infra Powershell\u out未将Powershell输出保存到chef中的变量

Chef infra Powershell\u out未将Powershell输出保存到chef中的变量,chef-infra,chef-recipe,Chef Infra,Chef Recipe,我试图在Chef中测试PowershellOut,以便从PS代码中获取一些值,然后将其保存到ruby变量中,以便在Chef代码中使用它。为了测试这一点,我创建了一个非常简单的场景: 厨师代码: ::Chef::Resource::PowershellScript.send(:include, Chef::Mixin::PowershellOut) testPO = <<-EOH $varo = "new22" $varo EOH newvar = power

我试图在Chef中测试PowershellOut,以便从PS代码中获取一些值,然后将其保存到ruby变量中,以便在Chef代码中使用它。为了测试这一点,我创建了一个非常简单的场景:

厨师代码:

::Chef::Resource::PowershellScript.send(:include,    Chef::Mixin::PowershellOut)

    testPO = <<-EOH
  $varo = "new22"
  $varo
EOH

newvar = powershell_out(testPO)

directory "C:\\Users\\Foo\\Desktop\\#{newvar}" do

  action :delete
end
没有红色错误,但我发现变量本身中存在某种错误代码:

目录[C:\Users\foo\Desktop]

您应该尝试newvar=powershell\u outtestPO.stdout.chomp

powershell\u out的工作原理类似于shell\u out,这是一个更好的文档

引用上述自述:

简单Shellout调用find1搜索.rb文件:

require 'mixlib/shellout'
find = Mixlib::ShellOut.new("find . -name '*.rb'")
find.run_command
如果一切顺利的话,结果就出来了

puts find.stdout
请记住,在chef recipe中,您不需要“mixlib/shellout”,因为chef已经为您做了,shell_out是mixlib::shellout.new的一种助手

您在食谱中加入powershell_的方法听起来不错,我不确定是否需要,但这取决于您对chef client的版本