CentLinux | Learn How to Install CentOS/Rocky Linux Servers

Sunday, September 15, 2019

Install Ansible AWX with Docker-Compose on CentOS 7

Install Ansible AWX with Docker-Compose on CentOS 7

In this article, you will learn how to install Ansible AWX with docker-compose on CentOS 7.

 

Table of Contents:

 

What is AWX Project? :

AWX Project or AWX is a web based console for Ansible. AWX is designed to make Ansible more usable for DevOps members of different technical proficiencies and skill sets. AWX is a hub for automation tasks. Ansible Tower is a commercial product supported by Red Hat, Inc. but derived from AWX upstream project, which is open source since September 2017. This makes AWX a good alternative of Ansible Tower.

Currently, stable version of AWX 7.0 has been released that requires a containerized environment to install and run. According to AWX Project Documentation, we can deploy AWX on following containerization platforms.

We are using Docker-Compose here, because it is relatively easy to setup and requires less hardware resources as compare to OpenShift and Kubernetes.

We have already installed Ansible control node on CentOS 7. Now, we are installing AWX with Docker-Compose on the same Ansible control node.

If you want to improve your knowledge about Ansible, then you should refer to Ansible Documentation or get a copy of Ansible Quick Start Guide: Control and monitor infrastructures of any size, physical or virtual by Packt Publishing.

Besides that, you can enroll in Ansible: Ansible Automation Masterclass: 2-in-1 at Udemy to be a master of Ansible in notime.

Install Ansible AWX with Docker-Compose on CentOS 7 


Environment Specification:

We are using three CentOS 7 virtual machines with following specifications.

  • CPU - 3.4 Ghz (2 Cores)
  • Memory - 4 GB
  • Storage - 60 GB
  • Hostname - ansible-01.centlinux.com
  • IP Address - 192.168.116.201 /24
  • Operating System - CentOS 7.6

 

Installing EPEL Yum Repository on CentOS 7:

Connect with ansible-01.centlinux.com by using ssh as root user.

AWX requires some packages that are available in EPEL (Extra Packages for Enterprise Linux) yum repository. Therefore, we are installing epel-release package by using yum command to enable EPEL.

# yum install -y epel-release

 

Installing Ansible AWX Prerequisites on CentOS 7:

AWX requires some prerequisite software packages, all of these packages are available in standard and EPEL yum repositories.

Therefore, we are Installing all prerequisite packages using a single yum command.

# yum -y install git gcc gcc-c++ nodejs gettext device-mapper-persistent-data lvm2 bzip2 python-pip

 

Installing Docker CE on CentOS 7:

Install Docker CE yum repository from Docker official website.

# yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

Since the Docker CE yum repository has been added, we can now install Docker CE using yum command.

# yum install -y docker-ce

Enable and start Docker service.

# systemctl enable --now docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

 

Installing Docker-Compose on CentOS 7:

PyPI (Python Package Index) is a software package repository of software written  in Python. PyPA (Python Package Authority) recommend use of PyPI for installation of Python software packages.

Therefore, we are installing docker-compose using pip command.

# pip install docker-compose

 

Installing Ansible AWX on CentOS 7:

Use git command to download AWX project from GitHub.

# git clone --depth 50 https://github.com/ansible/awx.git
Cloning into 'awx'...
remote: Enumerating objects: 8850, done.
remote: Counting objects: 100% (8850/8850), done.
remote: Compressing objects: 100% (4428/4428), done.
remote: Total 8850 (delta 5006), reused 6388 (delta 4234), pack-reused 0
Receiving objects: 100% (8850/8850), 11.30 MiB | 246.00 KiB/s, done.
Resolving deltas: 100% (5006/5006), done.

Go to ~/awx/installer directory and set a custom admin_password for AWX and PostgreSQL in inventory file.

# cd awx/installer
# sed -i 's|admin_password=.*|admin_password=Ahmer@1234|g' inventory

Generate a random key to use for encryption in inventory file.

# openssl rand -base64 30
ejv9P72oNvD4AtWLhOUTvpxfdIfKIid3skwuK+ES

Add the generated string as secret_key in inventory file.

# sed -i 's|secret_key=.*|secret_key=ejv9P72oNvD4AtWLhOUTvpxfdIfKIid3skwuK+ES|g' inventory

You can also customize many directives here, according to your requirements.

Verify the changes that we have made in inventory.

# grep -v '^#' inventory | grep -v '^$'
localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python"
[all:vars]
dockerhub_base=ansible
awx_task_hostname=awx
awx_web_hostname=awxweb
postgres_data_dir=/tmp/pgdocker
host_port=80
host_port_ssl=443
docker_compose_dir=/tmp/awxcompose
pg_username=awx
pg_password=awxpass
pg_admin_password=Ahmer@1234
pg_database=awx
pg_port=5432
rabbitmq_password=awxpass
rabbitmq_erlang_cookie=cookiemonster
admin_user=admin
admin_password=Ahmer@1234
create_preload_data=True
secret_key=ejv9P72oNvD4AtWLhOUTvpxfdIfKIid3skwuK+ES

Install AWX by using ansible-playbook command.

# ansible-playbook -i inventory install.yml

Ansible uses docker-compose to create the required containers by AWX. It will take time, according to your server's specs, therefore sit back and relax for a while.

After successful configuration of AWX and relevant containers. You can check the list of Docker processes to the running containers that are created by docker-compose for AWX.

# docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                                 NAMES
2c36037e1edf        ansible/awx_task:7.0.0       "/tini -- /bin/sh -câ¦"   2 minutes ago       Up 2 minutes        8052/tcp                                              awx_task
4af8c2a57530        ansible/awx_web:7.0.0        "/tini -- /bin/sh -câ¦"   2 minutes ago       Up 2 minutes        0.0.0.0:80->8052/tcp                                  awx_web
5580f44da60a        memcached:alpine             "docker-entrypoint.sâ¦"   2 minutes ago       Up 2 minutes        11211/tcp                                             awx_memcached
341e0660e369        ansible/awx_rabbitmq:3.7.4   "docker-entrypoint.sâ¦"   2 minutes ago       Up 2 minutes        4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 25672/tcp   awx_rabbitmq
6529a106ab89        postgres:10                  "docker-entrypoint.sâ¦"   2 minutes ago       Up 2 minutes        5432/tcp                                              awx_postgres

Allow HTTP service in Linux firewall, because the port 80 is mapped to the AWX container and it is used to access AWX web console.

# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success

Open URL http://ansible01.centlinux.com in a web browser.

01-ansible-awx-web-console-login

Login as Admin User.

02-ansible-awx-web-console-dashboard

We are reached at the dashboard of Ansible AWX.

We have successfully installed Ansible AWX with Docker-Compose on CentOS 7 server.

If you find this article useful? Consider supporting us by Buy Me A Coffee


© 2023 CentLinux. All Rights Reserved.