How to Install Ansible AWX in CentOS 8

Ansible AWX is an open-source version of Ansible Tower, a widely used configuration management tool. Ansible AWX is a web based IT Automation tool that makes it easier to deploy playbooks with its rich and easy to use UI.

In this tutorial, you will learn how to install Ansible AWX on CentOS 8.

Prerequisites:

  • Docker
  • Docker Compose
  • 4gb ram with 2V CPU's

There are other dependencies likes Redis, Postgres but they are automatically installed as part of the installation process.

Before proceeding with these steps make sure you switch to the root user

sudo su -

Step 1. Add required package repository

dnf install epel-release -y

Ansible Awx installation is based on running an ansible playbook and ansible is not available in the default repositories of CentOS,  in this step we are adding epel-release which is RedHat's repository.

Step 2. Install required packages

dnf install git python3-pip ansible gcc gcc-c++ nodejs gettext device-mapper-persistent-data lvm2 bzip2 

Step 3. Install docker and docker-compose

To install docker we need to add docker official repo to dnf  - which is a software package manager for linux distributions.

dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
 dnf install docker-ce --nobest -y

To enable docker service to run when server is restarted or rebooted , enable the docker service.

systemctl enable --now docker.service

We will now install docker-compose through pythons pip3 which is python3 package manager, but before that we need to make sure that python link is set correctly

alternatives --set python /usr/bin/python3
python --version

Make sure python version 3.X.X is installed.

pip3 install docker-compose

Step 4. Install Ansible AWX

We have all the prerequisites ready we can now install Ansible AWX from it's officially maintained GitHub repo.

For the setup to work properly clone the 17.X.X version from git using this command

git clone -b "17.1.0" https://github.com/ansible/awx.git

Once downloaded navigate to awx folder

cd awx/installer/

Generate a base64 secret.

openssl rand -base64 30

openssl rand - command will generate random password in base64 format which we will use as a secret, which is a required parameter in the inventory file , press insert on keyboard once the inventory file is open in a terminal, make the below changes carefully

Output: dgoQG1rd3LUV5JhNm05cRUZsC6P8iMwHlKQr/mqC

Update the secret key in inventory file.

vi inventory

uncomment - remove "#" and make the following changes in inventory file

  1. change secret_key = output of openssl rand -base64 30 command
  2. uncomment admin_password
  3. change awx_official=true

secret_key= output of openssl command

  • It's very important that this stay the same between upgrades or you will lose the ability to decrypt your credentials

admin_password

  • This will create or update a default admin (superuser) account in AWX, if not provided then these default values are used admin_user=admin admin_password=password

awx_official=true

  • To Build AWX with official logos, we need to clone awx-logos repo as a sibling of this project.
    Review the trademark guidelines at [link]

Save and exit the inventory file with esc + :wq

Use this command to start the installation process :

ansible-playbook -i inventory install.yml

Sit back and relax, this will start the installation process and based on the system can take some file, this will also download required docker images upwards of 1GB

TASK [local_docker : Run migrations in task container] and --> TASK [local_docker : Start the containers] - will take some time

Make sure the process is completed and nothing failed. If task preload data fails, re-run the ansible-playbook , make sure not to change the secret in the inventory file between re running the Ansible playbook.

To confirm all the containers are up and running, execute

sudo docker ps

To find the IP address of the server use command

ip addr show

To access the web UI, use the above ip adress in your browser

http://your-server-ip-adress

The Default username and password in the inventory file are

username: admin

password: password

Step 5. Sample Hello World playbook execution

To execute a sample playbook in AWX, below are the main steps.

  1. Create a playbook.
  2. Create a project in AWX which specifies the playbook location.
  3. Create an inventory which contains the remote server details.
  4. Create the credentials required to access the remote server.
  5. Finally create the template which has all the above details.

Lets go through each of these steps in detail.

Create a sample playbook in GitHub test.yml as below.

---
- hosts: all
  tasks:
  - name: Print
    debug:
     msg: "Hello World"

In AWX console, Navigate to Project in the left pane and click on Add to create a new project. Provide the details of the sample playbook in GitHub and click on Save.

Navigate to Inventories and click on Add->Add an inventory

Click on Save and click on Hosts to add servers to this inventory.

Navigate to Credentials and provide the details as below. Click save once done.

Navigate to Templates and click on Add->Add a job template. Provide all the details and click on save.

Finally click on Launch to launch the template. You will see a successful job run as below.

Conclusion

This completes the installation of open-source Ansible AWX on CentOS, note that since the docker containers are started with restart always policy from compose the containers will be up and running once the server restarts as well and data will persist as volumes are maintained even after restarts.

Mohammed Shahbaaz Shareef

Mohammed Shahbaaz Shareef

DevOps Practitioner with interest in Automation and Modernization