Skip to content

Installing .NET 4.6.1 on Windows Server 2012 R2 with Chef

Recently I was lucky enough to take part in a ‘hackathon’ with Chef, Microsoft and a partner company based in Norway. It was a great week working with some amazing people!

One of the challenges we faced was automating the installation of .NET 4.6.1; a requirement of the application that was the focus of the week long event. We struggled with automatically determining whether the package should be installed on the system, and then triggering a reboot in the correct order to allow IIS configuration to complete.

Here’s the Windows package resource we used to install .NET originally.

As you can see we needed to set the installer type to :custom because we were using a .exe package. In addition to this we passed some options to prevent an automatic reboot interrupting the Chef run, and to prevent user dialogues from interrupting the installation.

This worked, but running chef-client again would re-trigger the installation. Additionally, we had issues with IIS configuration (a different recipe) due to .NET installation being our first task. The flagged reboot prevented IIS features from fully enabling.

We decided to push the reboot out to the reboot resource with a notification from the Windows package resource.

We also changed the recipe order in default.rb to make .NET installation the last task; this fixed our reboot flag issue with IIS.

With this working we could now trigger a reboot from the successful installation of .NET as the last task in the chef-client run. Using request_reboot in the Reboot resource ensured a complete run before the machine going down.

We still had the problem of idempotency. Every time we converged the .NET installation kicked off, even if it was already installed at the correct version. To resolve this we added some logic. We settled on checking the registry for the build release number (matching 4.6.1) to either skip or trigger the windows_package resource.

Here’s the complete, working code.

2 Comments

  1. Jason Capriotti Jason Capriotti

    Nice work. I am working on a similar install, so stumbled over here. Two quick things i just learned (but am still testing). Both are in this readme: https://github.com/chef-cookbooks/windows

    First, it sounds like windows_package has been deprecated. Unfortunately their resource documentation must be out of date. Second, for “idempotentcy”, it suggests the “resource’s package_name should be the same as the ‘DisplayName’ registry value in the uninstallation data that is created during package installation”.

    • joe@grdnr.io joe@grdnr.io

      Hey Jason, glad it’s helpful. Yes, you can now use just package instead of windows_package. The resource names comes the default action. If you wee just to specify package ‘apache2’ on a Linux system you would of course have the package installed. You can use the documented options for the package resource to set source etc.

Leave a Reply

Your email address will not be published. Required fields are marked *