Managing ESXi host DNS using Ansible 2.0

With the release on Ansible 2.0 came several new VMware modules that leverage pyVmomi, one of which was vmware_dns_config. This modules runs directly against ESXi hosts, so if you have small lab with no vCenter (because reasons?) you can still use this module to ensure that the host(s) have the desired DNS servers.

As with the previous “vsphere” modules which I demoed last year on the #vBrownBag DevOps series, this tasks runs locally but leverage the previously mentioned pyVmomi instead of pySphere.

As of this writing, the Ansible documentation lists vSphere 5.5 as the only supported version. I am currently running the vCenter Server Appliance (VCSA) 6 in my lab, along with ESXi 6 hosts, though be aware YMMV.

Before you get started, I had a bit of head banging going on trying to determine how to setup Ansible properly. I had been using pyVmomi 5.5.0 as well as 6.0.0 without much success, Larry Smith in his testing found that 5.5.0-2014.1.1 seems to work (best), so when you install make sure you run

sudo pip install pyvmomi==5.5.0-2014.1.1

Now, once that is working, just a nice basic playbook in order to change DNS which you can find in my test playbook repo on GitHub. Here is a “before screenshot with one of my hosts having the incorrect DNS server:

Now, after running the playbook you can see that it has been corrected.