Install .NET Framework + Upgrade Powershell using Chef?

1.6k Views Asked by At

As some of you have seen, I'm a newbie with Chef, and there seems just so much to learn that it's hurting my head :(...

One of the things I ran into earlier testing was that some example recipes I found would fail because I am using Win2K8 as the NODE and that has Powershell V2 rather than Powershell V3.

So, as a kind of learning exercise, I would like to try to make a Chef cookbook to deploy PS V3 to Win2K8 R2. I think that I'll also need to get .NET Framework 4.5.x in order to install the PS V3 .msu (Windows6.1-KB2506143-x64.msu).

So, how do I make such a cookbook?

i've been looking around and found a dotnetframework cookbook and I've added that to my WORKSTATION.

I've also found this:

http://thinkofdata.blogspot.com/2014/07/installing-microsoft-net-framework.html

which seems like a different approach than using the dotnetframework cookbook?

I guess I'm confused about all of this? Are both of these approaches (using the dotnetframework cookbook vs. the one from the link above) "ok"?

Also, if I want to do the former, how do I actually do that? What do I need to put into my recipes/default.rb?

Finally, for now at least, what about executing the .msu after that, to do the PS V3 upgrade? How do I do that?

Sorry for all the questions (and hopefully I won't get flamed too much for them). I'll continue to bang away but hopefully you all can help point the way!

Thanks in advance, Jim

1

There are 1 best solutions below

0
On

You could use the windows_package command to be able to do this slightly differently (and not have to rely on a file download to determine whether or not something was installed on a box), but then you would have a dependency on the windows cookbook. This will work after downloading the Chef Development Kit and just using:

chef-apply install_powershell_4_0.rb

This also installs powershell 4.0 via the Windows Management Framework 4.0 installer rather than powershell 3.0 (which is why .NET framework 4.5 needs to be installed prior to installing WMF 4.0 because otherwise powershell isn't updated and stays at 2.0).

The server will reboot 3 times between each install, so you will have to run the chef-apply command to continue (or actually install chef client).

Here is the install_powershell_4_0.rb file:

#Create installs directory to house downloads
directory 'c:/installs' do  
end

#Install Windows 7 and Windows Server 2008 R2 Service Pack 1 (KB976932)
remote_file "c:/installs/windows6.1-KB976932-X64.exe" do
  source "http://download.microsoft.com/download/0/A/F/0AFB5316-3062-494A-AB78-7FB0D4461357/windows6.1-KB976932-X64.exe"
end

execute "c:/installs/windows6.1-KB976932-X64.exe /quiet" do
  action :nothing
  subscribes :run, resources(:remote_file => "c:/installs/windows6.1-KB976932-X64.exe")
end

#Install .NET 4.5
remote_file "c:/installs/dotNetFx45_Full_setup.exe" do
  source "http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_setup.exe"
end

execute "c:/installs/dotNetFx45_Full_setup.exe /quiet" do
  action :nothing
  subscribes :run, resources(:remote_file => "c:/installs/dotNetFx45_Full_setup.exe")
end

#Install Windows Management Framework 4.0
remote_file "c:/installs/Windows6.1-KB2819745-x64-MultiPkg.msu" do
  source "http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu"
end

execute "c:/installs/Windows6.1-KB2819745-x64-MultiPkg.msu /quiet" do
  action :nothing
  subscribes :run, resources(:remote_file => "c:/installs/Windows6.1-KB2819745-x64-MultiPkg.msu")
end

You then should be able to open a powershell command prompt and see 4.0 as the PSVersion via running:

$psversiontable