[chef] Re: RE: Windows and powershell_out


Chronological Thread 
  • From: Tensibai Zhaoying < >
  • To:
  • Subject: [chef] Re: RE: Windows and powershell_out
  • Date: Mon, 27 Oct 2014 12:43:17 +0100

The file don't exist when the only_if run  at compile time.  Run your powershell resource at compile time with end.run_action(:create) (see the default action I'm unsure)

At all it sounds you may be on the wrong way to achieve your goal, but without more details it's hard to give advices.



---- Iain Prior a écrit ----

Ok I made a little more progress..

But the problem is that the order is not correct, the file doesn’t exist when reportback runs..?



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

execute "reportback" do
  command "echo 1"
  node.normal[:ixserver][:Version_Installed] = File.read("C:\\windows\\temp\\fileversion.txt")
  only_if {  ::File.exists?("C:\\windows\\temp\\fileversion.txt") }
end



-----Original Message-----
From: Iain Prior [mailto: "> ]
Sent: Monday, October 27, 2014 1:07 PM
To: ">
Subject: [chef] Windows and powershell_out

Hi guys

I have managed to properly confuse myself well and truly!

Scenario: Basic Chef installation, server is Ubuntu 12.04, client is windows 2012 server.

What I want to do: Read the "version" property of a file into an attribute of a node.

What I've tried: You can see my attempt below. It seems that the PowerShellOut "mixin" is not available, but I'm too scared to add the windows and powershell cookbooks to my collection, because I understand that they are already included in the latest chef. So now I'm stuck! Help!!!

The powershell code below runs and creates the text file fine, but how do I get the value from the text file into the attribute?

The Code:

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_script 'filever2' do
  ::Chef::Recipe.send(:include, Chef::Mixin::PowershellOut)
  #include Chef::Mixin::PowershellOut
  node.normal[:ixserver][:Hello] = powershell_out("echo hello") end


I'm hoping you guys can help..

Many regards
Iain



Archive powered by MHonArc 2.6.16.

§