Skip to content

Ansible AWX – Deploying a VM with VMWare VCenter

Ansible AWX for those who have never heard or used it, is a server that simply runs Ansible playbooks. It is the open source community version of Ansible Tower and sits up stream, think of it like Red Hat’s Fedora. Pretty much AWX can do everything Tower can do. If you wish to find out more about AWX go here and check out the repo below.

There is a lot which can be said about AWX, and there is a whole process in getting it setup. However it isn’t the hardest thing to setup, and can even be setup to run on a Docker container – which is how I am using it.

Here are a few guides online I found helpful, remember you will need sufficient understanding of Ansible before proceeding as using AWX it is assumed you have this.

AWX Playbook


  • Physical Server
  • ESXi
  • VMWare VCenter Servers (Obtain a trial if your work doesn’t already have one that you can user)
  • VMWare VCenter VM templates created
  • Ansible & AWX

Github Repo


- name: AWX Deploy VM OS Host
  hosts: localhost
  connection: local
  gather_facts: no

    - name: Create a virtual machine from a template
        hostname: "{{ vcsa_hostname }}"
        username: [email protected]
        esxi_hostname: "{{ esxi_hostname }}"
        password: "{{ pwd }}"
        datacenter: mydc
        validate_certs: no
        folder: "{{ vcsa_folder }}"
        name: "{{ host_hostname }}"
        state: poweredon
        template: "{{ host_template }}"
        - size_gb: "{{ host_disk_size }}"
          type: "{{ host_disk_type }}"
          datastore: "{{ esxi_datastore }}"

## Customise this portion if you want unique hardware configuration - default is small
          memory_mb: "{{ host_memory }}"
          num_cpus: "{{ host_cpus }}"
          num_cpu_cores_per_socket: "{{ host_cores }}"
          scsi: paravirtual
          memory_reservation_lock: False
          mem_reservation: 2048
          hotadd_cpu: True
          hotremove_cpu: True
          hotadd_memory: True
          version: 14 # Hardware version of virtual machine
        - name: "{{ host_network }}"
        wait_for_ip_address: no
      delegate_to: localhost
      register: deploy

If you have used VMWare ESXi or VCenter enough, alot of the parameters here in this playbook look quite familiar. There is nothing too special in this playbook and it is pretty easy to get going with. Obviously modify username and datacenter.

All the variables you see here are actually going to be referenced in the survey that I am about to share. Depending on how customizable you need it to be you could make more survey variables here of course. In fact in the next post I will be giving more nobs to turn to allow us to do even more things.

AWX Survey

Now this in my opinion is where AWX really comes to life as an organizational tool. With survey you can open up AWX to people in support teams to do basic Ansible tasks without any real Ansible knowledge and even Ansible installed. You can get them also to run some of these tasks without ever knowing the username or password with the power of Ansible Vault.

As you will see I have survey question below for a password. This is because with the VMWare module it creates a Python API call to VMWare rather than a SSH connection. We can however use Ansible Vault and AWX built in for secure password storage, however for the sake of showing the flexibility of a survey it will be manually entered.

So this is the survey I made which uses all those aforementioned variables. How did I do this?

Here is a quick example, and I am sure you can fill in the rest of all the others I did.

  1. Create the Survey Question
  2. Multiple Choice Example

    As you can see in this example, I have also defined a default answer because the majority of hosts that I will most likely deploy this is enough allocated CPU’s, however do what you will with this of course.

    The important part really is just what the Answer Variable Name text is as this directly relates to… Yep you guessed it –

So there isn’t much to making a survey and linking it to variables. It is really that simple. Effectively just a simplified form builder.


I mentioned that these were a requirement, well templates are a very personal thing to many people in the industry. Like naming conventions, everyone has an opinion. How one should make a “gold” image for any given OS and deployment is a very interesting topical discussion. But again for the sake of simplicity I have CentOS, Ubuntu and Windows templates. I could have a thousand others but that’s not the point here.

These are very minimal templates and for the sake of this testing I am going with the centos8 template. But I could easily chose any of the other types here, and a million others if I so bothered to make that much choice…


Well ho ho ho, finally a network engineer talking about networking… Yeah nah… I am not even going to bother doing it here in this script in the traditional way and I am going to leave it out of the scope of this post. I am going to really just say that I am going to define here which Port Group the host will be associated with. In normal network terms this just means which VLAN is the host apart of.

But Daniel, how do I type in an IP address so I can add it into my 100% up to date and accurate IP spreadsheet?

Well for me IP Addressing will be sorted out by NetBox. Which I will touch on in a later post as this will dynamically provide the next IP address available and log it in the NetBox database. Effectively I don’t give two craps about the individual IP address, just where it is located – ie: Corporate, DMZ or Management.

I will also touch on how DNS will be updated within the respective domain (by the assigned NetBox IP). Again this is just highlighting my disdain to try and control and maintain IP addressing but let the computers do such a simple and basic task. Or maybe I am really just damn lazy… I dunno either way its how I like to roll.

For now lets just assume any hosts deployed into these networks get a DHCP IP and I won’t be configuring a static IP but using DNS to manage and maintain them.


Here is a quick GIF watching it in action.


In this quick example, I showed that it is very quick an easy to deploy a VM with Ansible AWX. In the next post I am going to show how we dynamically will allocate network configuration from another handy open source server – NetBox.

Ansible AWX has so many powerful features and I am constantly finding more and more I can do with it to take some of the repetitive tasks away. The most handy for me has been network device backups and linux host updates. Please share here any that you have made or seen in action which you have found to be very useful!

For those that have no desire to setup NetBox and would like to continue to provide the IP addresses, then add then review the Ansible module documentation for VMWare provided in the link below. Specifically refer to the last example which shows you how to assign IP addresses.

Hope you all have a great rest of your week and weekend and God Bless!

Leave a Reply

Skip to toolbar