,

10 min Windows 10 / Server 2019 build automation via OSDBuilder, autounattend.xml and Packer.IO

Intro

As IT pros, we’ve got no shortage of new / interesting and useful tools available to us. With the adoption of open-source software into consumer and enterprise environments, a lot of the tools are free! As long as you don’t need serious 24/7 support that is

How do you know which tools to use? COMMUNITY ! For me, that introduction came in 2017, I met Jonathan Pitre (twitter) while working in a previous job. Jon is Canada’s only CTA and has become a good friend since I met him in 2017. He opened my eyes to the “power of the community” that exists for EUC. Previously, I was aware of the EUC/CTA/CTP community by way of those awesome posts from the two Carl’s, but I wasn’t in the habit of regularly digesting the related blogs or going to events like Synergy or the like. Jon changed that REAL QUICK by letting me import his RSS blog list and also listed off a bunch of interesting tools he had used or was made aware of via the EUC community.

So, THANK YOU JON !!

This week, I checked another box off from Jon’s original list a few years back, Packer.io, and I’m glad I did. It’s amazing software. Also this week, I took https://osdbuilder.osdeploy.com for a spin, which provides a way to replace legacy dism commands and MDT

The challenges we face

Building windows 10 / server 201x images for cloning has the following challenges (at least as far as I’ve encountered)

  1. Human-error by hand cranking settings @ the virtual shell level
  2. Human-error by hand cranking settings post windows-build
  3. The amount of time it takes to apply windows updates once the base build is done
  4. Time that’s lost while waiting for steps 1/2/3 to complete

Each of the above challenges can be solved by combining a few simple tools that I will describe below

The solution

The solution I’ve found that worked for me is based on the open-source tool Packer

There’s a lot of marchitecture/jargon/nerd speak out there at the moment around dev-ops, CI/CD, “infrastructure as code. I’ve read plenty of posts online where the conversations contained so many acronyms, it made me question my command of the English language. It’s about time-savings and ensuring build consistency

The below steps are based on using Packer with vSphere, as it’s still the most common hypervisor for deploying Citrix workloads, and it happens to be what I use @ home on my VMUG licensed 3 node vSan cluster (<>shout out</>) There are official and community templates for Nutanix as well as all the major cloud platforms, but I’m only going to speak to what I know for this blog post, Packer + vSphere

When doing the work this week, I found that some of the reference blog pages and associated config files (.JSON/XML) for use with Packer had not been updated in a few years, so I definitely lost some time while troubleshooting, but, that’s how you learn! I can’t blame the authors of these blog posts ; how often do you go back and update your own blog posts? I’m guilty of this as well. If you’re reading this in the FUTURE and find that anything I’ve written below doesn’t work for you, please let me know in the comments or message me on twitter bird or email, I’ll try and help ya out! That’s community , baby !

Let’s get started with the proposed tools and proposed workflow at each stage to solve each of the 4 challenges I’ve listed above

Challenge 1: Standardizing VM shell settings
Here is our first case for use of the Packer tool. Packer uses .JSON based config files. These can be used to select the common shell values you select when manually creating a shell via the vSphere HTML5 client, or PowerCLI

Challenge 2: Standardizing windows install settings
Here, we will be using Microsoft autounattend.XML templates to pre-fill all the important settings that we would normally have to click / mouse through in a standard windows install.

Use of autounattend.XML files isn’t something new, but there are integration pieces that are possible by way of Packer integration which makes the autounttend.xml a lot more useful. You can use the Microsoft SDK and the Windows System image manager, but I’ve also got templates for Win 10 / Win 2019 server ready to use on my GIT hub HERE to save you having to create your own

Challenge 3: Windows updates last longer than it takes to make a drink a cup of coffee
OSDBuilder will be used to slipsteam in windows updates to our base ISO. As we are slipstreaming an offline image, we no longer need to reboot the live un-patched / out-of-date windows OS a bunch of times while we wait for each update to apply. This is a huge time-saver once combined with packer to attach the updated ISO

Challenge 4 – the time lost by waiting for each of the above 3 processes to complete
Again, Packer is here to help us out as the GLUE that ties it together! Packer is used to start step 1 and step 2, and thus fixes the issue with time lost in-between these steps

Detailed steps

Packer install/config

Windows Autounattnend.xml amendments

Packer JSON config amendments

NOTE: All guest OS types are listed HERE

Start Packer Build

Troubleshooting

Failures that occur with the PACKER JSON FILE

Failures that occur with the Windows Autounattend.xml file

Failures that occur after the windows build has completed, but before Packer has finished it’s final steps

vsphere-iso: Waiting for IP…
vsphere-iso: IP address: 192.168.1.180
vsphere-iso: Using winrm communicator to connect: 192.168.1.180
vsphere-iso: Waiting for WinRM to become available…

Closing

Please let me know if you found this blog post useful in the comments or on twitter

The process was pulled together on the week of July 20th , 2020. I read over a bunch of blog posts and consulted the excellent forums on the packer.io site. To get it all working, much of the refined process came down to trial/error. I believe practical knowledge is key to success in our industry

I’m really impressed with Packer thus far, the only “cost” was the time spent learning it, and will easily pay-out as I continue to use for build automation. Here, I’ve only covered using it with vSphere, but the packer folks support integration with dozens of the platforms, the sky is the limit

Have a nice day!

6 responses to “10 min Windows 10 / Server 2019 build automation via OSDBuilder, autounattend.xml and Packer.IO”

  1. Have you tried to
    Net stop “Vmware tool service name”
    Net start “Vmware tool service name”
    In the good old days this was the trick when installing printer drivers without rebooting.
    So perhaps it would help here as well

    Like

    • Hey Soren! That’s the thing, the VMware tools service doesn’t actually get installed on the first attempt! It’s quite frustrating, the VMware tools script I provided only adds another 15 seconds to the install, it just feels messy to use it. However, if the VMware tools service doesn’t get installed, the full packer build will eventually time-out, and the VM will be deleted by the packer.exe instance running on your remote machine

      Like

  2. G:\Packer.io>packer.exe build config/json/Win10_21H2_BIOS.json
    vsphere-iso: output will be in this color.

    ==> vsphere-iso: Creating VM…
    Build ‘vsphere-iso’ errored after 303 milliseconds 210 microseconds: error creating vm: A general system error occurred: PBM error occurred during PreCreateCheckCallback: Connection refused

    ==> Wait completed after 303 milliseconds 210 microseconds

    ==> Some builds didn’t complete successfully and had errors:
    –> vsphere-iso: error creating vm: A general system error occurred: PBM error occurred during PreCreateCheckCallback: Connection refused

    ==> Builds finished but no artifacts were created.

    Like

    • Hello! I’ve not seen this error before, apologies for my slow reply, I had not viewed my recent comments. How did you fix this error? For issues I wasn’t able to solve when i first started using Packer in 2021, I posted to the related hashicorp packer forums

      Like

  3. […] Last year, I wrote a long post about using Packer.IO to automate basic VMware shell creation and Win 10 / Win 2019 installation. At that time, I only ended up using the solution for re-builds on own home lab. This year, I’ve had the need to build golden images for multiple clients, each time, the process was manual and error prone as no automation was used. In the last week of Nov 2021, I decided to sit down last week and re-visit my packer / Powershell windows build templates.I’m very happy to share that I’ve got automation in place to deliver a fully built / base optimized / bi-lingual (En/Fr) / windows patched Windows EFI image in approx 25 minutes. Last year, the builds were about 10 mins, but didn’t do HAVE of what I have now. Let’s get into it!For reference, here was the blog post from last year on packer / windows build automation for VMware environments […]

    Like

Leave a comment