For those who seek help in different areas of software and hardware platform.

How To Install Ansible AWX on CentOS/RHEL 7/8

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. This tutorial will walk you through the steps to set up Ansible AWX using Docker on a CentOS/RHEL 7/8.


Prerequisites

To follow this tutorial along, you will need one (physical or virtual) machine with CentOS/RHEL 7/8 minimal installed, must have root user privileges.

Configure SELinux

By default, SELinux is enforcing in CentOS/RHEL 7/8. It is recommended to change SELINUX=enforcing to SELINUX=disabled to run Ansible AWX error free:
nano /etc/sysconfig/selinux
Replace the value "enforcing" with "disabled":
SELINUX=disabled
Save and close the file.

Reboot your machine to apply changes, when reboot complete, proceed with the below.

Install EPEL Repository

You will need to install the extra packages for enterprise Linux (EPEL) repository on your CentOS/RHEL 7/8:

Type below command if you are running CentOS/RHEL 8:
dnf -y install epel-release
Type below command if you are running CentOS/RHEL 7:
yum -y install epel-release

Install Required Packages

Type below to install these additional packages if you are running a CentOS/RHEL 8:
dnf -y install git gcc gcc-c++ ansible nodejs gettext device-mapper-persistent-data lvm2 bzip2 python3-pip python-docker nano
Type below if you are running a CentOS/RHEL 7:
yum -y install git gcc gcc-c++ ansible nodejs gettext device-mapper-persistent-data lvm2 bzip2 python3-pip python-docker nano

Install Docker

Type below to add Docker official repository on CentOS/RHEL 8:
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Type below to add Docker official repository on CentOS/RHEL 7:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Type below command to install Docker on CentOS/RHEL 8:
dnf -y install docker-ce
Type below command to install Docker on CentOS/RHEL 7:
yum -y install docker-ce
Next, start the Docker service and make it persistent even when system reboot with below command:
systemctl start docker
systemctl enable docker
Confirm that docker is active and running:
systemctl status docker
You will see similar output like below:


Type below to install Docker Compose on CentOS/RHEL 7/8:
pip3 install docker-compose
You will see the output like below:
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting docker-compose
  Downloading https://files.pythonhosted.org/packages/40/91/670b31a1c452cc5f3ed9e1ff905f6c4501a182551dfd8fa1981a8dca2d67/docker_compose-1.25.4-py2.py3-none-any.whl (136kB)
    100% |████████████████████████████████| 143kB 38kB/s
Collecting PyYAML<6>=3.10 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz (269kB)
    100% |████████████████████████████████| 276kB 14kB/s
Collecting requests<3>=2.20.0 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/1a/70/1935c770cb3be6e3a8b78ced23d7e0f3b187f5cbfab4749523ed65d7c9b1/requests-2.23.0-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 8.2kB/s
Collecting six<2>=1.3.0 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
Collecting websocket-client<1>=0.32.0 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/4c/5f/f61b420143ed1c8dc69f9eaec5ff1ac36109d52c80de49d66e0c36c3dfdf/websocket_client-0.57.0-py2.py3-none-any.whl (200kB)
    100% |████████████████████████████████| 204kB 27kB/s
Collecting dockerpty<1>=0.4.1 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/8d/ee/e9ecce4c32204a6738e0a5d5883d3413794d7498fe8b06f44becc028d3ba/dockerpty-0.4.1.tar.gz
Collecting docker[ssh]<5>=3.7.0 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/58/74/379a9d30b1620def158c40b88c43e01c1936a287ebb97afab0699c601c57/docker-4.2.0-py2.py3-none-any.whl (143kB)
    100% |████████████████████████████████| 153kB 15kB/s
Collecting jsonschema<4>=2.5.1 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/c5/8f/51e89ce52a085483359217bc72cdbf6e75ee595d5b1d4b5ade40c7e018b8/jsonschema-3.2.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 32kB/s
Collecting cached-property<2>=1.2.0 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/3b/86/85c1be2e8db9e13ef9a350aecd6dea292bd612fa288c2f40d035bb750ded/cached_property-1.5.1-py2.py3-none-any.whl
Collecting texttable<2>=0.9.0 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/ec/b1/8a1c659ce288bf771d5b1c7cae318ada466f73bd0e16df8d86f27a2a3ee7/texttable-1.6.2-py2.py3-none-any.whl
Collecting docopt<1>=0.6.1 (from docker-compose)
  Downloading https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-0.6.2.tar.gz
Collecting idna<3>=2.5 (from requests<3>=2.20.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/89/e3/afebe61c546d18fb1709a61bee788254b40e736cff7271c7de5de2dc4128/idna-2.9-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 13kB/s
Collecting chardet<4>=3.0.2 (from requests<3>=2.20.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 17kB/s
Collecting certifi>=2017.4.17 (from requests<3>=2.20.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/b9/63/df50cac98ea0d5b006c55a399c3bf1db9da7b5a24de7890bc9cfd5dd9e99/certifi-2019.11.28-py2.py3-none-any.whl (156kB)
    100% |████████████████████████████████| 163kB 5.9kB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1 .26="">=1.21.1 (from requests<3>=2.20.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/e8/74/6e4f91745020f967d09332bb2b8b9b10090957334692eb88ea4afe91b77f/urllib3-1.25.8-py2.py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 66kB/s
Collecting paramiko>=2.4.2; extra == "ssh" (from docker[ssh]<5>=3.7.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/06/1e/1e08baaaf6c3d3df1459fd85f0e7d2d6aa916f33958f151ee1ecc9800971/paramiko-2.7.1-py2.py3-none-any.whl (206kB)
    100% |████████████████████████████████| 215kB 134kB/s
Collecting pyrsistent>=0.14.0 (from jsonschema<4>=2.5.1->docker-compose)
  Downloading https://files.pythonhosted.org/packages/9f/0d/cbca4d0bbc5671822a59f270e4ce3f2195f8a899c97d0d5abb81b191efb5/pyrsistent-0.16.0.tar.gz (108kB)
    100% |████████████████████████████████| 112kB 137kB/s
Collecting attrs>=17.4.0 (from jsonschema<4>=2.5.1->docker-compose)
  Downloading https://files.pythonhosted.org/packages/a2/db/4313ab3be961f7a763066401fb77f7748373b6094076ae2bda2806988af6/attrs-19.3.0-py2.py3-none-any.whl
Collecting importlib-metadata; python_version < "3.8" (from jsonschema<4>=2.5.1->docker-compose)
  Downloading https://files.pythonhosted.org/packages/0f/b0/3302e1a1711aaa920e82b025ef07fb5fe81f09634e4f7af0fb4695b72cab/importlib_metadata-1.5.2-py2.py3-none-any.whl
Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages (from jsonschema<4>=2.5.1->docker-compose)
Collecting pynacl>=1.0.1 (from paramiko>=2.4.2; extra == "ssh"->docker[ssh]<5>=3.7.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/27/15/2cd0a203f318c2240b42cd9dd13c931ddd61067809fee3479f44f086103e/PyNaCl-1.3.0-cp34-abi3-manylinux1_x86_64.whl (759kB)
    100% |████████████████████████████████| 768kB 126kB/s
Collecting bcrypt>=3.1.3 (from paramiko>=2.4.2; extra == "ssh"->docker[ssh]<5>=3.7.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/8b/1d/82826443777dd4a624e38a08957b975e75df859b381ae302cfd7a30783ed/bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl (56kB)
    100% |████████████████████████████████| 61kB 244kB/s
Collecting cryptography>=2.5 (from paramiko>=2.4.2; extra == "ssh"->docker[ssh]<5>=3.7.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/45/73/d18a8884de8bffdcda475728008b5b13be7fbef40a2acc81a0d5d524175d/cryptography-2.8-cp34-abi3-manylinux1_x86_64.whl (2.3MB)
    100% |████████████████████████████████| 2.3MB 57kB/s
Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->jsonschema<4>=2.5.1->docker-compose)
  Downloading https://files.pythonhosted.org/packages/b2/34/bfcb43cc0ba81f527bc4f40ef41ba2ff4080e047acb0586b56b3d017ace4/zipp-3.1.0-py3-none-any.whl
Collecting cffi>=1.4.1 (from pynacl>=1.0.1->paramiko>=2.4.2; extra == "ssh"->docker[ssh]<5>=3.7.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/f1/c7/72abda280893609e1ddfff90f8064568bd8bcb2c1770a9d5bb5edb2d1fea/cffi-1.14.0-cp36-cp36m-manylinux1_x86_64.whl (399kB)
    100% |████████████████████████████████| 399kB 41kB/s
Collecting pycparser (from cffi>=1.4.1->pynacl>=1.0.1->paramiko>=2.4.2; extra == "ssh"->docker[ssh]<5>=3.7.0->docker-compose)
  Downloading https://files.pythonhosted.org/packages/ae/e7/d9c3a176ca4b02024debf82342dab36efadfc5776f9c8db077e8f6e71821/pycparser-2.20-py2.py3-none-any.whl (112kB)
    100% |████████████████████████████████| 112kB 35kB/s
Installing collected packages: PyYAML, idna, chardet, certifi, urllib3, requests, six, websocket-client, dockerpty, pycparser, cffi, pynacl, bcrypt, cryptography, paramiko, docker, pyrsistent, attrs, zipp, importlib-metadata, jsonschema, cached-property, texttable, docopt, docker-compose
  Running setup.py install for PyYAML ... done
  Running setup.py install for dockerpty ... done
  Running setup.py install for pyrsistent ... done
  Running setup.py install for docopt ... done
Successfully installed PyYAML-5.3.1 attrs-19.3.0 bcrypt-3.1.7 cached-property-1.5.1 certifi-2019.11.28 cffi-1.14.0 chardet-3.0.4 cryptography-2.8 docker-4.2.0 docker-compose-1.25.4 dockerpty-0.4.1 docopt-0.6.2 idna-2.9 importlib-metadata-1.5.2 jsonschema-3.2.0 paramiko-2.7.1 pycparser-2.20 pynacl-1.3.0 pyrsistent-0.16.0 requests-2.23.0 six-1.14.0 texttable-1.6.2 urllib3-1.25.8 websocket-client-0.57.0 zipp-3.1.0
Once you are finished with docker compose installation, type the below command to set python 3 in the environment variable:
alternatives --set python /usr/bin/python3
Type below command to verify whether python version 3 is default:
python --version
You should see output like below:
Python 3.6.8

Download Ansible AWX

You can download Ansible AWX latest release from the Git Hub repository using the below command:
cd ~
git clone https://github.com/ansible/awx.git

When download complete, type below command to generate a secret key using openssl and that key will be used to encrypt inventory file:
openssl rand -base64 30
You will see the output similar to the following:


Copy your key and save it for later use in the inventory file.

Install Ansible AWX

You need to edit inventory file like below:
cd ~/awx/installer/
nano inventory
Find the following directives, uncomment them by removing #, replace these highlighted values with yours:
admin_password=Set_Your_Password_Here
secret_key=Paste_Your_Secret_Key_Here
awx_alternate_dns_servers="8.8.8.8,8.8.4.4"
project_data_dir=/var/lib/awx/projects
Save and close the file when you are finished.

Next, create a pgdocker directory under /var/lib/
mkdir /var/lib/pgdocker
Type the following command to install AWX:
cd ~/awx/installer
ansible-playbook -i inventory install.yml
This will create and start all the required Docker containers for Ansible AWX.

You can verify the running containers with the following command:
docker ps

Add Firewall Rules

You will need to add following rules to allow http and https service to pass through firewalld:
firewall-cmd --zone=public --add-masquerade --permanent
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Access AWX Web Interface

Open up your preferred web browser and type the http://your-server-ip in the address bar, you will be redirected to the login page like below:


Log in with the admin username and password which you have defined in the inventory file, you should see the default dashboard like below:



Wrapping up

Now that you have Ansible AWX running, you can now administer and manage your Ansible project easily using the AWX web interface.
Share:

9 comments:

  1. Awesome job and well explained!
    A novice with no linux expertise could do it.

    ReplyDelete
  2. could you please help me with this error?

    [root@centos7 installer]# ansible-playbook -i inventory install.yml

    PLAY [Build and deploy AWX] ********************************************************************************************************

    TASK [Gathering Facts] *************************************************************************************************************
    fatal: [localhost]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"setup": {"failed": true, "module_stderr": "/usr/bin/env: python3: No such file or directory\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 127}}, "msg": "The following modules failed to execute: setup\n"}

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

    [root@centos7 installer]#

    -Docker is Running.

    [root@centos7 ~]# systemctl enable docker
    Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

    [root@centos7 ~]# systemctl status docker
    â—� docker.service - Docker Application Container Engine
    Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
    Active: active (running) since Sun 2020-09-06 04:45:20 UTC; 44s ago
    Docs: http://docs.docker.com
    Main PID: 1532 (dockerd-current)
    CGroup: /system.slice/docker.service
    ├─1532 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=do...
    └─1545 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-int...

    Sep 06 04:45:19 centos7 dockerd-current[1532]: time="2020-09-06T04:45:19.906672982Z" level=warning msg="Docker could not en...ystem"
    Sep 06 04:45:19 centos7 dockerd-current[1532]: time="2020-09-06T04:45:19.935201401Z" level=info msg="Graph migration to con...conds"
    Sep 06 04:45:19 centos7 dockerd-current[1532]: time="2020-09-06T04:45:19.936058581Z" level=info msg="Loading containers: start."
    Sep 06 04:45:20 centos7 dockerd-current[1532]: time="2020-09-06T04:45:20.077597010Z" level=info msg="Firewalld running: false"
    Sep 06 04:45:20 centos7 dockerd-current[1532]: time="2020-09-06T04:45:20.246261411Z" level=info msg="Default bridge (docker...dress"
    Sep 06 04:45:20 centos7 dockerd-current[1532]: time="2020-09-06T04:45:20.307628249Z" level=info msg="Loading containers: done."
    Sep 06 04:45:20 centos7 dockerd-current[1532]: time="2020-09-06T04:45:20.324019711Z" level=info msg="Daemon has completed i...ation"
    Sep 06 04:45:20 centos7 dockerd-current[1532]: time="2020-09-06T04:45:20.324139460Z" level=info msg="Docker daemon" commit=...1.13.1
    Sep 06 04:45:20 centos7 dockerd-current[1532]: time="2020-09-06T04:45:20.330828761Z" level=info msg="API listen on /var/run....sock"
    Sep 06 04:45:20 centos7 systemd[1]: Started Docker Application Container Engine.
    Hint: Some lines were ellipsized, use -l to show in full

    -Ansible Version,

    [root@centos7 installer]# ansible --version
    ansible 2.9.10
    config file = /etc/ansible/ansible.cfg
    configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/lib/python2.7/site-packages/ansible
    executable location = /usr/bin/ansible
    python version = 2.7.5 (default, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

    ReplyDelete
    Replies
    1. You need to Install python3 to fix this issue.

      Delete
    2. I understand, but if I have it installed but not as the main language in my OS CentOs. I'm going to make a new attempt and share my results with you, thanks for the contribution.

      Delete
    3. Hi Friend.

      Thanks for your valuable input, I have installed Python 3 with SCL to start the download and installation of ansible. now I see the containers in Docker and load the Ansible web page. but what happens is that it stays loading and never finishes updating. analyzing the log I see the following. I appreciate you can help me.

      -log: ^
      2020-09-07 08:56:41,654 INFO exited: dispatcher (exit status 1; not expected)
      2020-09-07 08:56:41,654 INFO exited: dispatcher (exit status 1; not expected)
      2020-09-07 08:56:42,657 INFO spawned: 'dispatcher' with pid 15325
      2020-09-07 08:56:42,657 INFO spawned: 'dispatcher' with pid 15325
      2020-09-07 08:56:43,659 INFO success: dispatcher entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
      2020-09-07 08:56:43,659 INFO success: dispatcher entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
      2020-09-07 08:56:45,417 WARNING awx.main.dispatch.periodic periodic beat started
      Traceback (most recent call last):
      File "/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
      return self.cursor.execute(sql, params)
      psycopg2.errors.UndefinedTable: relation "main_instance" does not exist
      LINE 1: SELECT (1) AS "a" FROM "main_instance" WHERE "main_instance"...
      ^
      The above exception was the direct cause of the following exception:


      Thanks for your valuable input, I have installed Python 3 with SCL to start the download and installation of ansible. now I see the containers in Docker and load the Ansible web page. but what happens is that it stays loading and never finishes updating. analyzing the log I see the following. I appreciate you can help me.

      Thank you.

      Delete
    4. Pay attention to this (psycopg2.error) and try to fix it. Most probably you are missing psycopg2 package.

      Delete
  3. Thank you very much friend. now AWX is running without problem. it's time to automate some things.

    Follow this link to solve:

    https://stackoverflow.com/questions/41611551/python-cant-install-psycopg2-on-centos-7

    ReplyDelete
  4. hi, is there any solution for this error?
    TASK [local_docker : Start the containers] **************************************************************************************************************************************************
    fatal: [localhost]: FAILED! => {"changed": false, "msg": "Configuration error - Named volume \"var/lib/pgdocker/10/data:/var/lib/postgresql/data:Z\" is used in service \"postgres\" but no declaration was found in the volumes section."}

    ReplyDelete
    Replies
    1. You have to declare ./var/lib/pgdocker/10/data in .yml file under volume section. Follow the link for reference:

      https://docs.docker.com/compose/compose-file/#volume-configuration-reference

      Delete

Comments with links will not be published.

Video Tutorials