Testing Ansible AWX with Windows Hosts
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.
- From the root folder of the cloned Ansible-Windows repo, SSH into the Ansible Control VM:
vagrant ssh ansible01
- Switch to root user:
sudo su
- Navigate to the default Project folder location:
cd /var/lib/awx/projects
- 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:
Log in to AWX Web Interface
- Open a browser and navigate to the AWX login page http://192.168.10.10.
- Log in to AWX using the default username
admin
and default passwordpassword
.
Create a new Project
- Navigate to the Projects page, within the Resources menu.
- Create a new Project called
Manual Project
. - Ensure the
SCM TYPE
field isManual
. - The
PLAYBOOK DIRECTORY
drop-down menu should now show theansible
folder that was copied from the Vagrant share in a previous step:
Create a new Inventory
- Navigate to the Inventories page, within the Resources menu.
- Create a new Inventory called
Manual Project Inventory
:
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:
- From the Ansible Control VM command prompt, enter into the
awx_task
container’s Bash shell:docker exec -it awx_task bash
- Navigate to the
ansible
Project folder location that was previously copied:cd /var/lib/awx/projects/ansible
- Import existing inventory file:
awx-manage inventory_import --source=./hosts --inventory-name="Manual Project Inventory" --overwrite --overwrite-vars
- The hosts from the imported inventory file now appear within the
Manual Project Inventory
:
- The variables from the imported inventory file also appear within the
Manual Project Inventory
, though theansible_user
andansible_password
variables should be removed, and a Credential created for this purpose:
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:
- Navigate to the Credentials page, within the Resources menu.
- Create a new Credential called
Windows Hosts
. - Ensure the
CREDENTIAL TYPE
field isMachine
. - Enter
vagrant
for both the username and password:
Create a new Job Template
All the previous resources are now selected within a Job Template:
- Navigate to the Templates page, within the Resources menu.
- Create a new Template called
Manual Job Template
. - Select
Manual Project Inventory
from theINVENTORY
field search pop-up box. - Select
Manual Project
from thePROJECT
field search pop-up box. - Select
site.yml
from thePLAYBOOK
field drop-down menu. - Select
Windows Hosts
from theCREDENTIALS
field search pop-up box.
Starting the Job Template
Once a Job Template has been created, it can be started by clicking the rocket icon highlighted below:
Reviewing the Job Logs
After the Job has finished, the logs can be viewed as shown below:
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