Deploying VSphere Virtual Machines Using Ansible
Deploying VSphere Virtual Machines Using Ansible
by admin
With that done we can now use Ansible to interact with vSphere. The module I’ll be using in this post is called
vmware_guest, which allows us to use Ansible to create virtual machines, deploy from template, power virtual
machines on and off and modify, rename and remove virtual machines.
To deploy a virtual machine from template, we could use a playbook similar to the following:
---
# create a new VM from a template
**********************************************************************************************
**************************************************
**********************************************************************************************
*******************************************
changed: [localhost]
**********************************************************************************************
***************************************************
PLAY RECAP
**********************************************************************************************
*********************************************************
Notice that we are outputting the IP address attribute of the new virtual machine with the ‘IP address info’ task. With
the IP known we could use it to connect to the VM with Ansible to perform some OS configuration tasks, ultimately
enabling us to provision and new virtual machine, and configure its OS/applications etc in the same playbook. Next
time, I’ll cover a bit around Ansible Vault, which is used to avoid showing sensitive data such as usernames and
passwords in a playbook.