Ansible: Automating Windows Server 2012 r2 installation in vCenter
Automating your VMware infrastructure using Ansible
In my last article,we seen that how we can automate CentOS 7 installation using Ansible and Kickstart file in the vCenter environment.
In this article, let us know automate installation of Windows server 2012 r2 in your vCenter environment. Windows installation can be automated using answer file. These answer file can be created using Windows System Image Manager (Windows SIM). We will not go in details of how to create Autounattend.xml since it out-of-scope for this article.
For automated Windows server 2012 r2 installation, you will require —
- Windows server 2012 r2 installation DVD
- Pre-generated Autounattended.xml
In order to feed answer file to Windows installation, we will need to provide Autounattended.xml file to setup via ISO file or USB stick. Let us know create an ISO file with Autounattended.xml.
# ls windows_config
Autounattend.xml# mkisofs -o win_unattended.iso -J -r windows_config/
Total translation table size: 0
Total rockridge attributes bytes: 281
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used 0
186 extents written (0 MB)
Here, Autounattend.xml is located in windows_config directory. With mkisofs
command we can create an ISO file with this file inside it. Copy both Windows Installation DVD and newly created ISO file win_unattended.iso
to the given datastore.
You can find this answer file here — https://raw.githubusercontent.com/Akasurde/shared_contents/master/windows_unattended_xml/Autounattend.xml
You will notice that this file contains FirstLogonCommands
block which automates installation of Ansible WinRM Setup and VMware Tools installation. This block looks like this —
Now, we will use vmware_guest
module to create blank VM with two CDROMs attached to it.
Once you run this playbook, you can see Windows VM is created in vCenter. After VM is created, vmware_guest
will poweron the virtual machine and start the installation process using two CDROMs attached.
Once installation is successful, VM is prepared for Ansible and can be used for further automation.
Thanks for reading, and Happy Automating.