Latest

Sunday, 15 September 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? Don't you mind support us by Buy Me A Coffee


20 comments:

  1. I don't know how you've managed to do this, but i don't believe it is that simple...

    The ansible docker-compose module only works when running with ansible python interpreter set to python3.
    But there is no libselinux-python available under python3, so docker-compose may work but then nothing else does... even the copy file module fails.

    ReplyDelete
    Replies
    1. Yes you need to install the Python3 interpreter, which also installs pip3.
      Make sure to set the python interpreter to python3, by default python2 is picked up.
      After you have installed python3, edit the first line of the inventory file and replace python by python3, see below:
      localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python3"
      Also make sure to replace all pip commands by pip3 (e.g. pip3 install ...).

      Delete
  2. Hi, after installation the login page compains abount missing license with the following message:
    "Failed to access license information. GET returned status:"

    How can I solve this?
    Thanks

    ReplyDelete
    Replies
    1. Please check the permissions on project directory.

      Delete
    2. Was trying to find the project directory at the default location (/var/lib/awx/project) which I am not able to find. I am getting the same error.

      Delete
    3. You should find the installation directory of AWX, the project directory is located therein.

      Delete
  3. Hi, after installation i got the error "This site can’t be reached192.168.1.14 refused to connect." Please help.

    ReplyDelete
    Replies
    1. Hi, Please ensure that the port 80/tcp is allowed in Linux firewall.

      Delete
    2. Hi,

      we have to allow port on container where application is running. Or on host machine where docker is installed.

      Delete
  4. Hey, I'm getting the following error when running the playbook:

    LAYBOOK: install.yml **********************************************************************************************
    1 plays in install.yml

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

    TASK [Gathering Facts] *********************************************************************************************
    task path: /root/awx/installer/install.yml:2
    fatal: [localhost]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"setup": {"failed": true, "module_stderr": "/usr/bin/env: ‘python’: 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

    ReplyDelete
  5. Hi,

    Follow all the step to install ansible awx.
    Please is there any post installation step not mention in document.

    Because i have checked log of awx_web it showing error.

    ile "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
    File "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
    File "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
    django.db.utils.OperationalError: could not connect to server: No route to host
    Is the server running on host "postgres" (172.18.0.2) and accepting
    TCP/IP connections on port 5432?

    [pid: 128|app: 0|req: 1/1] 172.18.0.1 () {40 vars in 594 bytes} [Fri Dec 6 12:41:58 2019] GET / => generated 3868 bytes in 60299 msecs (HTTP/1.1 500) 2 headers in 105 bytes (1 switches on core 0)

    ReplyDelete
    Replies
    1. Please ensure that network configurations are correct. Also allow the service port 5432/tcp in Linux firewall.

      Delete
  6. Trying to install this on an Azure based Redhat 7.7 Linux server I am stopped in the tracks with the Python.h not found issue during 'pip install docker-compose'. Please advise.



    # pip install docker-compose
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o
    _posixsubprocess.c:16:20: fatal error: Python.h: No such file or directory
    #include "Python.h"
    ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
    Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-H_YEOZ/subprocess32/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-K0G6jz-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-H_YEOZ/subprocess32/

    ReplyDelete
    Replies
    1. Install "Development Tools" group to rectify this error.

      # yum groupinstall 'Development Tools' -y

      Delete
  7. Hi Ahmer,

    I'm getting below error when checking logs by using below command.
    # docker logs -f awx_web

    [root@ansible installer]# docker logs -f awx_web
    Using /etc/ansible/ansible.cfg as config file
    Using /etc/ansible/ansible.cfg as config file
    127.0.0.1 | FAILED! => {
    "ansible_facts": {
    "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "elapsed": 301,
    "msg": "Timeout when waiting for postgres:5432"
    }
    Using /etc/ansible/ansible.cfg as config file
    127.0.0.1 | FAILED! => {
    "ansible_facts": {
    "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "elapsed": 301,
    "msg": "Timeout when waiting for memcached:11211"
    }
    Using /etc/ansible/ansible.cfg as config file
    127.0.0.1 | FAILED! => {
    "ansible_facts": {
    "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "elapsed": 301,
    "msg": "Timeout when waiting for rabbitmq:5672"
    }
    Using /etc/ansible/ansible.cfg as config file
    An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TCP/IP connections on port 5432?
    127.0.0.1 | FAILED! => {
    "ansible_facts": {
    "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "msg": "unable to connect to database: could not connect to server: No route to host\n\tIs the server running on host \"postgres\" (172.18.0.4) and accepting\n\tTCP/IP connections on port 5432?\n"

    [root@ansible installer]# docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    c93de51cd98d ansible/awx_task:9.0.1 "/tini -- /bin/sh -c…" 41 minutes ago Up 38 minutes 8052/tcp awx_task
    1ec2fa798ce2 ansible/awx_web:9.0.1 "/tini -- /bin/sh -c…" 41 minutes ago Up 38 minutes 0.0.0.0:80->8052/tcp awx_web
    2fbcd374a979 ansible/awx_rabbitmq:3.7.4 "docker-entrypoint.s…" 41 minutes ago Up 38 minutes 4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 25672/tcp awx_rabbitmq
    28ce2cb6254c memcached:alpine "docker-entrypoint.s…" 41 minutes ago Up 38 minutes 11211/tcp awx_memcached
    44a2c03709be postgres:10 "docker-entrypoint.s…" 41 minutes ago Up 38 minutes 5432/tcp awx_postgres


    regards,
    Rahul Rawat

    ReplyDelete
    Replies
    1. Please check you network configurations. It looks like that either your address isn't resolvable or there isn't any route defined.

      Delete
  8. [root@localhost awx]# ls
    API_STANDARDS.md config INSTALL.md MANIFEST.in requirements
    awx CONTRIBUTING.md ISSUES.md pre-commit.sh setup.py
    awx_collection DATA_MIGRATION.md LICENSE.md pyproject.toml tools
    awxkit DCO_1_1.md Makefile pytest.ini tox.ini
    CHANGELOG.md docs manage.py README.md VERSION

    after installing awx from github, I'm not able to find installer directory. What should I do?

    ReplyDelete
    Replies
    1. Hi, In the above procedure, the AWX is not really installed on your host machine, instead it is started as a Docker container. Therefore, you could not find the installation directory.

      Delete

© 2022 CentLinux. All Rights Reserved.