Azure Provisioning using Ansible AWX (Tower)

1 minute read

Scenario

You’ve installed and tested Ansible locally, then installed Ansible AWX (Open Source Ansible Tower) using Docker, and finally tested Ansible AWX with Windows Hosts.

You now want to test Azure Provisioning using Ansible AWX.

Solution

Building upon the work I did in previous posts, I’ve created a pre-configured Vagrant lab that will build a local Ansible Control VM on your computer.

You can then run a Job Template from the AWX Web UI to provision a CentOS VM and all associated resources in Azure.

TL;DR - Step by Step Build and Test Guide

If you don’t care how I built this Vagrant lab, simply visit https://github.com/adamrushuk/ansible-azure and follow the step by step README to test Azure Provisioning using Ansible AWX.

If you’d like to know more, read on.

Vagrant Lab

I used the latest CentOS Vagrant box (‘bento/centos-7.6’) for the base VM, and created several provisioning scripts, detailed below:

install_common.sh

This script will:

  1. Enable the EPEL repo
  2. Install common utilities

install_ansible_azure.sh

This script will:

  1. Install Ansible
  2. Install Azure prereqs and modules

install_docker_ce.sh

This script will:

  1. Install Docker CE (required for Ansible AWX)

install_ansible_awx.sh

This script will:

  1. Install Docker SDK for Python
  2. Clone latest AWX repo
  3. Stage custom AWX inventory config file
  4. Install Ansible AWX
  5. Install Ansible Tower CLI tool

configure_ansible_awx.sh

This script will:

  1. Create a new SSH key
  2. Configure Ansible AWX using Tower CLI (SSL verification disabled)
  3. Wait for AWX Web Server to be online
  4. Wait for AWX Demo Data import to finish
  5. Copy projects folder from Vagrant share into AWX project folder
  6. Create an Azure Project resource in AWX
  7. Create an Azure Inventory resource in AWX
  8. Create an Azure Credential resource in AWX, using the Azure credentials from azure_ansible_credentials.yml
  9. Create an Azure Job Template in AWX, using the above resources

azure_ansible_credentials.yml

This configuration file contains values needed for an Azure credential:

  • subscription (your Azure Subscription ID)
  • client (the Application ID from an Azure Service Principle)
  • secret (the Password from an Azure Service Principle)
  • tenant (your Azure Tenant ID)

Support

I’m happy to help with any questions or build errors, so please submit a new issue if you require any assistance.