How to Install Ansible AWX using Docker Compose (AWX Container) 20.04

How to Install Ansible AWX using Docker Compose (Build Ansible AWX Container) 20.04. In this guide we will introduce Ansible AWX with it’s main advantages then move onto installation with Docker Compose.

AWX is a Ansible Tower based tool that offers a web interface and a task engine that helps users to manage their Ansible project form the central place.

Let’s start with how to Install Ansible AWX using Docker Compose (Build Ansible AWX Container) 20.04.

Introduction to Ansible AWX

AWX is an open source project behind Red Head Ansible Tower. It is designed to offer developers access to the latest features and the opportunity to directly collaborate with the Ansible Tower Engineering team. It is a code development branch that undergoes minimal and quality engineering testing.

Enterprise adoption has some drawbacks that include a lack of signed images for using it in the enterprise, support being offered. Also it is complex or lack of actual versioning being present with upgrades. However, Ansible AWX is a powerful open source, freely available project that enables organizations to test and use Ansible AWX in a lab, development, or other POC environment.

The greatest benefit it provides its users is that they can use all the enterprise features for an unlimited number of nodes.

Advantages of Ansible AWX

With the AWX it also has some of the following interesting facts and features that prove to be beneficial while dealing with the day to day software management problems:

  • Dashboard – The dashboard of AWX provides a display for that is going on in the Ansible environment. It includes: 1. The number of successful and failed playbook job status. 2. Number of projects and the sync status. 3. Number of inventories. 4. Graph of the playbook currently running in the Ansible environment.
  • Support Multiple Clouds – You can integrate AWX with several clouds, including AWX & Azure, CGP, and many more.
  • Organized – It enables you to divide the users into teams and groups.
  • Centralized LogsAWX can be integrated with multiple logging tools, like ELK & Loggly.
  • Role Based Access Control & Authentication – With the help of AWX, you can set up roles for our teams according to the least privilege policies. It can also be integrated with LDAP and Active Directory (AD) servers.
  • Increased Efficiency And Security– AWS provides you with better operational control and security. This way, it tends to increase the security of your team as well.
  • Job Scheduling – It helps you in scheduling planned jobs.
  • ScalabilityAnsible AWX allows you to add or control nodes in the AWS cluster based on your requirements.
  • User Activity Tracking – With the help of Ansible AWS, you can also track the activities of the users, like who runs the job, what type of job they run, when they run the job, and a lot more.

Follow this post to show you how to install Ansible AWX using Docker Compose on Ubuntu 20.04.

Install Ansible AWX using Docker Compose on Ubuntu 20.04

Prerequisites

  • A server running Ubuntu 20.04 in your system.
  • Minimum 4 GB of RAM and 3.4 GHz CPU with 2 Cores.
  • A root password is setup on your server.

Install Required Dependency

Before starting, you will need to install some required dependency including, Node.js, NPM, Ansible and other on your server.

Firstly install Node.js and NPM using the following command:

				
					apt install nodejs npm -y
npm install npm --global
				
			

Next, install Python dependency with the following command:

				
					apt install python3-pip git pwgen -y
				
			

Following step is to install the Ansible package by running the following command:

				
					apt install ansible -y
				
			

Once Ansible is installed, verify the Ansible version using the following command:

				
					ansible --version
				
			

You will get the following output:

				
					ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]

				
			

Install Docker and Docker Compose

Secondly  you will need to install the Docker and Docker Compose package on your server. By default, the latest version of Docker is not available on Ubuntu default repository. So you will need to add the Docker CE repository to APT.

First of all  install required dependencies using the following command:

				
					apt install apt-transport-https ca-certificates curl software-properties-common -y
				
			

Then add the Docker CE repository with the following command:

				
					curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
				
			

Floowing is to update the repository cache with the following command:

				
					apt update -y
				
			

After that install the Docker CE and Docker Compose using the following command:

				
					apt install docker-ce -y
apt install docker-compose -y
				
			

Now verify the Docker version using the following command:

				
					docker --version
				
			

You will get the following output:

				
					Docker version 20.10.17, build 100c701
				
			

You can also verify the Docker Compose version using the following command:

				
					docker-compose --version
				
			

You should see the following output:

				
					docker-compose version 1.25.0, build unknown
				
			

Next, you will need to install the Docker Compose Python module that matches the Docker Compose version. You can install it using the following command:

				
					pip3 install docker-compose==1.25.0
				
			

Download Ansible AWX

In here please download the Ansible AWX from the Git Hub repository using the wget command:

				
					wget https://github.com/ansible/awx/archive/17.1.0.zip
				
			

Once the AWX is downloaded, unzip the downloaded file with the following command:

				
					unzip 17.1.0.zip
				
			

Please navigate to the AWX directory and generate the secret key using the following command:

				
					cd awx-17.1.0/installer
pwgen -N 1 -s 40
				
			

You should see the generated key in the following output:

				
					eMyJLuLsDTlqjOinT1mJnZA7u9NkvlqCvAtmmiz3
				
			

Install Ansible AWX

Before starting, you will need to edit the Ansible inventory file and define your admin username, password and secret key:

				
					nano inventory
				
			

Change the following lines:

				
					admin_user=admin
admin_password=yourpassword
secret_key=eMyJLuLsDTlqjOinT1mJnZA7u9NkvlqCvAtmmiz3
				
			

Save and close the file when you are finished then install the Ansible AWX using the following command:

				
					ansible-playbook -i inventory install.yml
				
			

This command will create a docker-compose.yml file, download all required container images from the Docker Hub and start it as shown below:

				
					TASK [local_docker : Create Redis socket directory] ******************************************************************************************
ok: [localhost]

TASK [local_docker : Create Docker Compose Configuration] ************************************************************************************
ok: [localhost] => (item={'file': 'environment.sh', 'mode': '0600'})
changed: [localhost] => (item={'file': 'credentials.py', 'mode': '0600'})
ok: [localhost] => (item={'file': 'docker-compose.yml', 'mode': '0600'})
ok: [localhost] => (item={'file': 'nginx.conf', 'mode': '0600'})
ok: [localhost] => (item={'file': 'redis.conf', 'mode': '0664'})

TASK [local_docker : Render SECRET_KEY file] *************************************************************************************************
ok: [localhost]

TASK [local_docker : Remove AWX containers before migrating postgres so that the old postgres container does not get used] *******************
ok: [localhost]

TASK [local_docker : Run migrations in task container] ***************************************************************************************
changed: [localhost]

TASK [local_docker : Start the containers] ***************************************************************************************************
changed: [localhost]

TASK [local_docker : Update CA trust in awx_web container] ***********************************************************************************
changed: [localhost]

TASK [local_docker : Update CA trust in awx_task container] **********************************************************************************
changed: [localhost]

TASK [local_docker : Wait for launch script to create user] **********************************************************************************
ok: [localhost -> localhost]

TASK [local_docker : Create Preload data] ****************************************************************************************************
changed: [localhost]

PLAY RECAP ***********************************************************************************************************************************
localhost                  : ok=21   changed=8    unreachable=0    failed=0    skipped=73   rescued=0    ignored=1   

				
			

Access Ansible AWX

  1. Now, open your web browser and access the Ansible AWX using the URL http://your-server-ip. You will be redirected to the AWX login screen:

2. Provide your admin username, password and click on the login button. You should see the AWX dashboard on the following screen:

Verify AWX Containers

You can use the Docker Compose command line to verify all AWX containers. First, change the directory to the awxcompose with the following command:

				
					cd ~/.awx/awxcompose
				
			

Verify all running container using the following command:

				
					docker-compose ps
				
			

You should see the following output:

				
					    Name                  Command               State                  Ports                
--------------------------------------------------------------------------------------------
awx_postgres   docker-entrypoint.sh postgres    Up      5432/tcp                            
awx_redis      docker-entrypoint.sh /usr/ ...   Up      6379/tcp                            
awx_task       /usr/bin/tini -- /usr/bin/ ...   Up      8052/tcp                            
awx_web        /usr/bin/tini -- /bin/sh - ...   Up      0.0.0.0:80->8052/tcp,:::80->8052/tcp
				
			

To get a list of all Docker images, run the following command:

				
					docker images
				
			

You should see the following list:

				
					REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
redis         latest    3edbb69f9a49   4 days ago      117MB
postgres      12        ffc079081fed   10 days ago     373MB
centos        8         5d0da3dc9764   10 months ago   231MB
ansible/awx   17.1.0    599918776cf2   16 months ago   1.41GB

				
			

To check the AWX logs, run the following command:

				
					docker-compose logs 
				
			

You will get the following output:

				
					awx_postgres | 2022-07-23 03:40:01.616 UTC [94] STATEMENT:  SELECT "conf_setting"."id", "conf_setting"."created", "conf_setting"."modified", "conf_setting"."key", "conf_setting"."value", "conf_setting"."user_id" FROM "conf_setting" WHERE ("conf_setting"."key" = 'OAUTH2_PROVIDER' AND "conf_setting"."user_id" IS NULL) ORDER BY "conf_setting"."id" ASC  LIMIT 1
awx_postgres | 2022-07-23 03:40:01.617 UTC [94] ERROR:  relation "conf_setting" does not exist at character 158
awx_postgres | 2022-07-23 03:40:01.617 UTC [94] STATEMENT:  SELECT "conf_setting"."id", "conf_setting"."created", "conf_setting"."modified", "conf_setting"."key", "conf_setting"."value", "conf_setting"."user_id" FROM "conf_setting" WHERE ("conf_setting"."key" = 'OAUTH2_PROVIDER' AND "conf_setting"."user_id" IS NULL) ORDER BY "conf_setting"."id" ASC  LIMIT 1
awx_postgres | 2022-07-23 03:41:52.654 UTC [1] LOG:  received fast shutdown request
awx_postgres | 2022-07-23 03:41:52.656 UTC [1] LOG:  aborting any active transactions
awx_postgres | 2022-07-23 03:41:52.658 UTC [89] FATAL:  terminating connection due to administrator command
awx_postgres | 2022-07-23 03:41:52.673 UTC [1] LOG:  background worker "logical replication launcher" (PID 83) exited with exit code 1
awx_postgres | 2022-07-23 03:41:52.680 UTC [108] FATAL:  terminating connection due to administrator command
awx_postgres | 2022-07-23 03:41:52.683 UTC [78] LOG:  shutting down
awx_postgres | 2022-07-23 03:41:52.800 UTC [1] LOG:  database system is shut down
awx_postgres | 
awx_postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
awx_postgres | 
awx_postgres | 2022-07-23 03:41:54.783 UTC [1] LOG:  starting PostgreSQL 12.11 (Debian 12.11-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
awx_postgres | 2022-07-23 03:41:54.784 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
awx_postgres | 2022-07-23 03:41:54.784 UTC [1] LOG:  listening on IPv6 address "::", port 5432
awx_postgres | 2022-07-23 03:41:54.787 UTC [1] LOG:  listening on Unix socket "https://net.cloudinfrastructureservices.co.uk/var/run/postgresql/.s.PGSQL.5432"
awx_postgres | 2022-07-23 03:41:54.820 UTC [26] LOG:  database system was shut down at 2022-07-23 03:41:52 UTC
awx_postgres | 2022-07-23 03:41:54.927 UTC [1] LOG:  database system is ready to accept connections
				
			

If you want to stop all running containers, run the following command:

				
					docker-compose down
				
			

You can start all of them again with the following command:

				
					docker-compose up -d
				
			

That’s great! Thank you for reading our article about How to Install Ansible AWX using Docker Compose (Build Ansible AWX Container) 20.04.

How to Install Ansible AWX using Docker Compose 20.04 Conclusion

In this post, we explained how to install Ansible AWX container using Docker Compose on Ubuntu 20.04. You can now easily manage all your Ansible projects from the AWX web based interface. AWS can be integrated with slack and email as well. By doing so, you tend to acquire notifications concerning the job status updates immediately after adding the call back plugin.

Read more about Ansible in our blog category here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

4 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x