Managing VMware vSphere guests with Ansible Tower

March 2, 2015 by Mark Phillips

There are lots of ways to enable self-service VMs within an organisation - what some might call 'a private cloud'. However, these usually require layers and layers of complex software. What if you could leverage your existing hypervisor and 15 lines of code to do the same? And what if those 15 lines became an even simpler single click?

Ansible Core contains a module for managing virtual machines in VMware vSphere environments called vsphere_guest. Using this one module we can talk to an existing vSphere instance to create new VMs, clone VM templates, and control and delete VMs. Couple up a simple playbook with Ansible Tower and we can do some pretty amazing things with very little effort.

Here's our playbook to create a new virtual machine from a template in vSphere:


The really important bit that's doing the work is the 15 lines associated with the 'Create VM from template' task. Note the extensive use of variables in this play to give us lots of flexibility. We'll make use of this in Tower in just a moment.

Tower 2.1 introduced 'Surveys', which are a great way to create interactive forms for a given play. The form can prompt for variable information to make running a flexible play simpler:


Setting up multiple choice questions is also really easy:


Here's a short video of the Job Templates in action:



There are many more ways to extend this simple functionality - Tower's job scheduler could automatically run a play to 'scavenge' unused VMs, for example (put a fact on the host to say it's done with, and you protect against automatically killing a VM still in use).


Ansible Tower


Mark Phillips

Mark Phillips is a UK-based Product Manager. With almost a quarter of a century of industry experience, he has designed and engineered automated infrastructures at every level - from a handful of hosts in startups, to the tens of thousands in investment banks. You can follow him on twitter at @thismarkp.


See All

rss-icon  RSS Feed

AF 2022 - Blog static promo