Build a Windows lab with VirtualBox, Packer and Vagrant, adding sysprep (part 2)
september 17, 2015
In my former article I elaborated on how to create a lab with Windows servers quickly using Vagrant, Packer and Virtualbox. What I did not realize at that time is that the box I created had 2 issues:
- The box is not sysprepped. The sysprep is mandatory if you want to create a Domain Controller and are adding boxes to the domain. You’ll end up with 2 boxes with the same SID.
- The MAC address is cloned for every Vagrant machine that is based on the box. This becomes a problem if you want to place the hosts in a bridged network.
Then I went and Googled (after trying in vain myself) and found this repository: https://github.com/mefellows/packer-community-templates. Someone has already done it.
Here is a link to the json file: https://gist.github.com/jacqinthebox/cd3dcbf4b220c70de956.
Copy this file to the packer-windows folder and save it as ‘windows_2012_r2_sysprep.json’
Make sure you copy the Autounattend_sysprep.xml file from \packer-community-templates\answer_files\2012_r2 to the \packer-windows\answer_files\2012_r2 folder.
Now you can run packer build -only virtualbox-iso windows_2012_r2_sysprep.json. And grab a coffee.
The MAC address can be set in the Vagrant file for each machine. First you need to know what the name is of the network interface for the bridge.
Then you can insert the name of the nic in the Vagrantfile like this (see the marked lines):
Vagrant.require_version ">= 1.6.2" $root_provision_script = <<'ROOT_PROVISION_SCRIPT' & $env:windir\system32\tzutil /s "W. Europe Standard Time" ROOT_PROVISION_SCRIPT Vagrant.configure("2") do |config| config.vm.define "dsc01" config.vm.box = "windows_2012_r2" config.vm.hostname = "dsc01" config.vm.provider :virtualbox do |v, override| v.gui = true end end config.vm.network :forwarded_port, guest: 3389, host: 3391, id: "rdp", auto_correct: true config.vm.network :forwarded_port, guest: 22, host: 2223, id: "ssh", auto_correct: true config.vm.network "public_network", :bridge => 'Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.30)', :mac => "5CA1AB1E0001" config.vm.provision "shell", inline: $root_provision_script end
So there it is.
2 Replies to “Build a Windows lab with VirtualBox, Packer and Vagrant, adding sysprep (part 2)”
Great set of articles, I came here after running into the same issue with the cloning feature of Vagrant for a windows 2012r2 server. I’m starting to read up on your first article in this series. The documentation on managing windows servers through Vagrant is a bit dispersed, sometimes out of date and to be honest I’m not that interested in running windows servers anymore. I just need a quick lab setup now and then so running 180 days trial copies via an automated process is something I’m willing to invest in.
thanks for the write up,
[…] Build a Windows lab with VirtualBox, Packer and Vagrant, adding sysprep (part 2) […]