Ansible Tower in Vagrant

A lot of times during my job I found myself with the need of Ansible Tower testing environments.

In the last few weeks I created a Vagrant script to actually automate it.

As this is a single host installation, which is usually more than enough for the majority of tests I do, the Vagrant file is very easy:

Vagrant.configure(2) do |config|

    # Set machine size
    config.vm.provider :libvirt do |domain|
        domain.memory = 2048
        domain.cpus = 1

    # Tower/PgSQL machine
    config.vm.define "tower" do |tower| = "centos/7"

    # Ansible Tower configuration
    config.vm.provision "ansible" do |ansible|
        ansible.playbook = "playbook.yaml"


I basically create a 2Gb of RAM machine leveraging libvirt and run an Ansible Playbook on it. The reason I created a 2Gb of RAM machine and I’ve not tried to shrink it further is because the Ansible Tower installation checks for 2Gb of RAM, and I wanted to create something easy. I’m sure I could patch the installer to accept a 1Gb machine, but it’s not worth the effort to me. Also, in my usual usage of the computer I rarely go below 11Gb free memory, so I’m not too concerned in giving 2Gb to my VM.

In the Vagrant file we were calling an Ansible Playbook to install Ansible Tower. Here is the Ansible Playbooks:

- hosts: all
  name: Install Ansible Tower
    version: '3.1.3'
    - name: Ensure EPEL is enabled
        name: epel-release
        state: present
      become: True
    - name: Set hostname
        name: '{{ inventory_hostname }}' 
      become: True
    - get_url:
        url: '{{ version }}.tar.gz'
        dest: '/tmp/ansible-tower-setup-{{ version }}.tar.gz'
    - unarchive:
        remote_src: True
        src: '/tmp/ansible-tower-setup-{{ version }}.tar.gz'
        dest: /tmp
    - copy:
        remote_src: True
        dest: '/tmp/ansible-tower-setup-{{ version }}/inventory'
        src: /vagrant/inventory
    - shell: ./
        chdir: '/tmp/ansible-tower-setup-{{ version }}'
      become: True

As you can see is a very straightforward Ansible Playbook which ensures that EPEL is enabled (since is required by Ansible Tower installer), then proceeds to set the hostname matching Vagrant hostname. After this Ansible Tower installer gets downloaded, uncompressed, the inventory file gets imported and finally the installer gets run.

To make the process working we do need a valid Ansible Inventory file. I use the following one:

localhost ansible_connection=local

localhost ansible_connection=local





# Needs to be true for fqdns and ip addresses

As you can immagine from the Ansible Inventory file, the user admin will end up having the password admin.

To run the whole thing you’ll just need to vagrant up the stack and you’ll get your Ansible Tower installation. Remember that - at least at the moment of writing - Ansible Tower is close source and will require a valid license to actually work. The first time you’ll login it will ask you for a valid license that you can provide (if you already have one) or require one here.

For complete and updated code, you can have a look here.