- From: Iain Prior <
>
- To: "
" <
>
- Subject: [chef] RE: Re: Re: RE: Windows and powershell_out
- Date: Tue, 28 Oct 2014 04:46:32 +0000
- Accept-language: en-US, sv-SE
- Acceptlanguage: en-US, sv-SE
Hi all
Thanks for the help and advice so far. I managed to get it working, but I
understand that I'm missing some important concept here. I am trying to set
an attribute on the node that I can see in the website that will show me that
the process has completed correctly. Hence getting the version of the
installed file and reporting back.
Now what is the "right" way to do this? How do I tell the chef-server that
the recipe has completed correctly?
Here is the working version of the code if anyone needs it in future. The
problem was that the File.read was running too early in the process, I think
just after compile and before the "convergence" step that runs all the code.
Putting it in a ruby_block makes it wait until it's turn to run.
#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
Many thanks
Iain
-----Original Message-----
From: Julian C. Dunn
[mailto:
Sent: Tuesday, October 28, 2014 7:42 AM
To:
Subject: [chef] Re: Re: RE: Windows and powershell_out
On Mon, Oct 27, 2014 at 7:43 AM, Tensibai Zhaoying
<
>
wrote:
>
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)
Not sure what the problem is here exactly but I just wanted to clarify that
guards don't run at compile time; they run at execute time, so that can't be
the problem.
Could you try using "| Out-File C:\windows\temp\fileversion.txt"
rather than the ">" redirection?
- Julian
--
[ Julian C. Dunn
<
>
* Sorry, I'm ]
[ WWW:
http://www.aquezada.com/staff/julian * only Web 1.0 ]
[
gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]
Archive powered by MHonArc 2.6.16.