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).