Reputation: 2372
Ok, so im stuck. I'm trying to read a .Net file's version attribute and save that into a node's attribute. So I can see the version of the intalled program on the server side in the node's attributes.
I can run a powershell script like this:
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
I understand that the powershell and windows cookbooks are now part of chef's basic install, but it seems that powershell_out is missing. I tried including it like this, but no joy.
powershell 'filever2' do
include Chef::Mixin::PowershellOut
node.normal[:ixserver][:Hello] = powershell_out("echo hello")
end
I have all the little bits, but I can't seem to get them to gel correctly.
Upvotes: 0
Views: 3678
Reputation: 1701
It's been moved to the windows cookbook.
From the powershell cookbook:
The Chef::Mixin::PowershellOut mixin has been moved to the windows cookbook.
And from the windows cookbook:
PR 115 - require Chef::Mixin::PowershellOut before using it
Upvotes: 0
Reputation: 2372
Ok so the problem was that the file_read was running in the early stages of the recipe and not at then end when it was supposed to. Here is the working version for any that may need to read a file into a attribute and post it back to the server.
#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
Upvotes: 1
Reputation: 54211
This is not how Chef works. Resources don't have return values in this manner and most can't set attributes. You'll have to use a ruby_block resource or LWRP, but the complexity of this makes it difficult to explain. I don't think powershell_out
is an actual thing in Chef, did you just assume that exists because of shell_out
or did you see it in the documentation somewhere?
Upvotes: 0