Ansible ESXi Playbook

Here is the playbook for what I would normally considering including in an ESXi Setup. As always with scripts and such things, use at your own peril and test it in a safe environment before just running it on your production system.

I have the variables file in a separate post here.

The section below is the first part, the — signals that this is an asible file. We define a few steps and also name the part of the playbook. This generally makes it relatively easy to follow where you are in the playbook in case something goes wrong. This being around 350 lines long is useful for troubleshooting and also documentation.

The next section here is mainly about the management network, we need to add vmnic1 to the configuration, take care of the Management Portgroup. Add DNS and configure vmk0. We also remove the ‘VM network Portgroup that is created by default.
Next we setup vSwitch 1-4 and add the relevant nics to these switches.
After this we start to configure the various Portgroups:
After the portgroups we add the advanced configurations, in this case I also added settings for NetApp and NFS. One thing to note here, the ESXiSehllTimeOut setting to 0 is not a recommended setting. This was something that was included as a request from a customer.
Next we remove the local datastore from the setup. This could have been added earlier but for now I just go with the order of the file as it was created. There are in some cases reasons why the order is as it is.
Next it is time for adding the portgroups for VMs, these are added with a loop and the first part is the Name, then the assignmend.
Nest is which switch we assign it to.
Lastly we add a VLAN ID.
After this we configure ntp and snmp services and enable these services:
Then I tend to create a folder for the new server where it is deployed to. You can test all the things are setup correctly and then move it to the right final folder in your setup. The host is also added to the vCenter here.
The final steps are that we disable IPv6, which I rarely end up using so far. We put the host in maintenance mdoe and then it’s rebooted to apply the IPv6 change.
That is pretty much it.
After the script runs you should end up with a host inside vCenter and pretty much ready to run.
Ansible is a great way to automate these things and verify that you have a uniform setup across environments.
Here is the copy of the files I used here. As mentioned above, use at your own peril 🙂