Testing Ansible AWX with Windows Hosts

2 minute read

Scenario

After installing Ansible AWX using Docker to test within a Windows environment, I wanted to configure and test Ansible AWX.

Solution

Although there is an excellent Quick Setup Guide available for Ansible Tower (the commercial version of AWX), I’ll be going over the steps I took to import files from the already cloned repo (https://github.com/adamrushuk/Ansible-Windows/).

Copy Project Files

As AWX was installed using Docker, the Ansible files need copying into the default Project folder location /var/lib/awx/projects, so the hosts Inventory file can be imported from inside the awx_task container.

  1. From the root folder of the cloned Ansible-Windows repo, SSH into the Ansible Control VM:
     vagrant ssh ansible01
    
  2. Switch to root user:
     sudo su
    
  3. Navigate to the default Project folder location:
     cd /var/lib/awx/projects
    
  4. Copy the whole ansible folder from the Vagrant share to the current projects folder:
     cp -R /vagrant/ansible/ ansible
    

The folder structure should be as shown below:
Ansible AWX Project folder

Log in to AWX Web Interface

  1. Open a browser and navigate to the AWX login page http://192.168.10.10.
  2. Log in to AWX using the default username admin and default password password.

Create a new Project

  1. Navigate to the Projects page, within the Resources menu.
  2. Create a new Project called Manual Project.
  3. Ensure the SCM TYPE field is Manual.
  4. The PLAYBOOK DIRECTORY drop-down menu should now show the ansible folder that was copied from the Vagrant share in a previous step: Create a new Project in AWX

Create a new Inventory

  1. Navigate to the Inventories page, within the Resources menu.
  2. Create a new Inventory called Manual Project Inventory:
    Create a new Inventory in AWX

Import Inventory File

Now the AWX Inventory called Manual Project Inventory has been created, the existing Inventory file called hosts can be imported using the steps below:

  1. From the Ansible Control VM command prompt, enter into the awx_task container’s Bash shell:
     docker exec -it awx_task bash
    
  2. Navigate to the ansible Project folder location that was previously copied:
     cd /var/lib/awx/projects/ansible
    
  3. Import existing inventory file:
     awx-manage inventory_import --source=./hosts --inventory-name="Manual Project Inventory" --overwrite --overwrite-vars
    
  4. The hosts from the imported inventory file now appear within the Manual Project Inventory:
    Imported hosts
  5. The variables from the imported inventory file also appear within the Manual Project Inventory, though the ansible_user and ansible_password variables should be removed, and a Credential created for this purpose:
    Imported hosts

Create a new Credential

As previously mentioned, the ansible_user and ansible_password variables have beed removed from the Manual Project Inventory, so a new Credential is required:

  1. Navigate to the Credentials page, within the Resources menu.
  2. Create a new Credential called Windows Hosts.
  3. Ensure the CREDENTIAL TYPE field is Machine.
  4. Enter vagrant for both the username and password:
    Windows Hosts Credential

Create a new Job Template

All the previous resources are now selected within a Job Template:

  1. Navigate to the Templates page, within the Resources menu.
  2. Create a new Template called Manual Job Template.
  3. Select Manual Project Inventory from the INVENTORY field search pop-up box.
  4. Select Manual Project from the PROJECT field search pop-up box.
  5. Select site.yml from the PLAYBOOK field drop-down menu.
  6. Select Windows Hosts from the CREDENTIALS field search pop-up box.

Job Template

Starting the Job Template

Once a Job Template has been created, it can be started by clicking the rocket icon highlighted below:
Job Template

Reviewing the Job Logs

After the Job has finished, the logs can be viewed as shown below:
Job Logs

What’s Next?

This post showed the mostly manual steps required for configuring and testing Ansible AWX. In future I will look into the API and CLI configuration options.

Leave a comment