0

好的,所以我卡住了。我正在尝试读取 .Net 文件的版本属性并将其保存到节点的属性中。所以我可以在节点的属性中看到服务器端安装程序的版本。

我可以像这样运行 powershell 脚本:

powershell_script 'filever' do
    code <<-EOH
       [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\\Program Files\\Internet Explorer\\iexplore.exe").FileVersion > C:\\windows\\temp\\fileversion.txt
       get-content -Path  C:\\windows\\temp\\fileversion.txt
    EOH
end

我知道 powershell 和 windows 食谱现在是厨师基本安装的一部分,但似乎 powershell_out 不见了。我试着像这样包含它,但没有快乐。

powershell 'filever2' do
  include Chef::Mixin::PowershellOut
  node.normal[:ixserver][:Hello] = powershell_out("echo hello")
end

我有所有的小东西,但我似乎无法让它们正确凝胶。

4

3 回答 3

1

好的,问题是 file_read 在配方的早期阶段运行,而不是在它应该运行的时候结束。这是任何可能需要将文件读入属性并将其发布回服务器的工作版本。

#Check the installed version
powershell_script 'filever' do
code <<-EOH
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\\Program Files\\Internet Explorer\\iexplore.exe").FileVersion > c://chef//fileversion.txt
EOH
end

#report back after all is done
ruby_block "reportback" do
  block do
    encoding_options = {
        :invalid           => :replace,  # Replace invalid byte sequences
        :undef             => :replace,  # Replace anything not defined in ASCII
        :replace           => '',        # Use a blank for those replacements
        :universal_newline => true       # Always break lines with \n
      }
      node.normal[:ixserver][:Version_Installed] = File.read("C:\\chef\\fileversion.txt").encode(Encoding.find('ASCII'), encoding_options)
  end
end
于 2014-10-28T04:48:51.240 回答
0

它已被移至 Windows 食谱。

来自powershell 食谱

Chef::Mixin::PowershellOut mixin 已移至windows食谱。

Windows 食谱中:

PR 115 - 使用前需要 Chef::Mixin::PowershellOut

于 2015-02-23T21:06:48.383 回答
0

这不是厨师的工作方式。资源没有这种方式的返回值,并且大多数不能设置属性。您必须使用 ruby​​_block 资源或 LWRP,但其复杂性使其难以解释。我不认为这powershell_out是 Chef 中的实际事物,您只是假设它存在是因为shell_out还是您在文档中的某个地方看到了它?

于 2014-10-27T17:35:36.830 回答