Ansible role based deployment for windows guest along with os customization, WinRM and AD integration
In enterprise level, just deploying the windows vm is always not enough. The vm need to connect AD to support enterprise logins and many guest os level changes needed like configuring DNS, NTP, adding multiple hard disks, applying the disk labels etc. Using ansible modules these steps can be done easily.
Its always a good practice to write role based ansible playbooks and using tags so that when needed a specific role can be called using its respective tag.
In this example we will perform the below tasks using ansible roles:
- VM Deployment
- Guest OS customization
- Windows Updates
- Software Upload
- Software Installation
- VM Deletion
Lets go through the following example to understand how these requirements can be achieved:
Each role consists of multiple tasks in it which will be performed sequentially. These roles will use specific ansible modules which are part of ansible collections. Under roles folder we have subfolders for each role which will have atleast 2 folders in it.
- tasks
- meta
In each role, multiple ansible modules can be used and that can be defines in the 'meta/main.yaml' file of that specific role. Let's see an example:
The modules that are used in 'guestoscustom' roles, few of them are part of 'community.windows' and remaining are part of 'ansible.windows' collections. Hence we need to include both under the meta files.
If you need to install software in the guest os then its required to keep them in the ansible provision server under some location so that push method can be used to copy them to the guest OS and then installation can be performed.
As the guest os is an windows operating system, we need to have pywinrm package installed in the ansible provision server along with pywinrm[credssp] which will be used for authentication to the guest OS. Its always good to use HTTPS port of WinRM 5986 for the communication which required a certificate. It can either be a self signed SSL or a CA signed one. And in the dynamic_inventory file can have the connection & authentication type.
At the time of guest os deployment, following powershell script can be used to generate the self signed certificate:
For the VM deployment I have used the VMware as a Virtualized platform and ansible has great support for it. All ansible collections for specific platform can be accessed using the below links:
And for any issues related to above modules, always feel free to report in their respective github links.
Comments
Post a Comment