Install and configure Ansible AWX on CentOS 8

To
You can download this article in PDF format via the link below to support us.

Download the guide in PDF format

turn off
To

To
To

As a system administrator, you are likely to repeat certain tasks every day. These tasks take up a lot of time, which could have been spent elsewhere. What if you can solve the problem once, and then automate the solution? This is where Ansible excels, and once you see its benefits, you will never look back. Ansible is a simple and powerful IT automation engine, thousands of companies are using it to reduce the complexity of the environment and accelerate DevOps plans.

Whether it’s application deployment, daily server maintenance, configuration management, continuous delivery, orchestration, or any repetitive tasks you can describe, Ansible can handle it for you. In order to add beauty to the beast, AWX (Ansible Web eXecutable) provides a Web-based user interface, REST API and a task engine built on Ansible. The AWX project is an open source community project sponsored by Red Hat, allowing users to better control their use of the Ansible project in the IT environment. AWX is an upstream project from which the Red Hat Ansible Tower product was eventually derived.

“Don’t wait. The time will never be right.” –Napoleon Hill

prerequisites

Before running the deployment, you need to install the following components in your local environment

  • Ansible version 2.8+
  • The latest version of Docker
  • docker Python module
  • GNU Make
  • Git version 1.8.4+
  • Python 3.6+
  • Node 10.x LTS version

Now, we should be ready to roll up our sleeves, put on our boots, and go to work.

Step 1: Install Epel version repository and dependencies

We need the package from the Epel repository, so let’s install it as follows:

sudo dnf -y install epel-release

AWX has some packages that need to be dependencies. We can install all of them by running the following commands.

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

Disable SELinux

If you can handle SELinux easily, this is optional. To disable it, run the following command and restart the server.

sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

Step 2: Install Docker and Docker Compose

AWX is supported and can only be run as a containerized application using Docker images deployed to OpenShift clusters, Kubernetes clusters or docker-compose. In this guide, we will use Docker to get AWX up and running.

First, before installing Docker, download the Docker repository file to /etc/yum.repos.d/docker-ce.repo and update the RPM index cache.

sudo curl  https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
sudo yum makecache 
sudo dnf -y  install docker-ce --nobest

Start and enable the Docker service to start at boot time and check if it is running

$ sudo systemctl enable --now docker
$ 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 Mon 2020-07-27 20:21:51 UTC; 5s ago
     Docs: https://docs.docker.com
 Main PID: 52836 (dockerd)
    Tasks: 22
   Memory: 49.8M
   CGroup: /system.slice/docker.service
           ├─52836 /usr/bin/dockerd -H fd://
           └─52843 containerd --config /var/run/docker/containerd/containerd.toml --log-level info

The docker group has been created, but no users have been added to the group. Add your user to this group to run docker commands without sudo.

sudo usermod -aG docker $USER

Find more information about installing Docker and Docker Compose on CentOS 8 to install Docker and docker-compose on Cent0S 8 servers.

Next, we will use the pip3 command to install the docker-compose and docker python modules as shown below.

sudo pip3 install -U docker docker-compose

Confirm the installed version.

$ docker-compose version
 docker-compose version 1.26.2, build unknown     
 docker-py version: 4.2.2
 CPython version: 3.6.8
 OpenSSL version: OpenSSL 1.1.1c FIPS  28 May 2019

Step 3: Clone AWX from git

So far, we have covered all the prerequisites for AWX to breathe. We can finally clone and install Ansible AWX safely. Let’s use the following command to get the AWX file from Git.

cd ~
git clone --depth 50 https://github.com/ansible/awx.git

Go to the installer directory

There is a configuration file in the installer directory, we need to modify and execute it, so please navigate to that directory.

cd ~/awx/installer/

Before editing the manifest file, generate the secret encryption key to be used by running the following command.

$ pwgen -N 1 -s 30
yBs76VurxRiBwtDHrrF2JJlLgVrcv3

Edit the manifest file and customize it to suit your environmental needs.

$ vim inventory

[all:vars]
dockerhub_base=ansible
awx_task_hostname=awx
awx_web_hostname=awxweb
postgres_data_dir="~/.awx/pgdocker"
host_port=80
host_port_ssl=443
docker_compose_dir="~/.awx/awxcompose"
pg_username=awx
pg_password=awxpass
pg_database=awx
pg_port=5432
admin_user=admin
admin_password=SuperSecret
create_preload_data=True
awx_alternate_dns_servers="8.8.8.8,8.8.4.4"
secret_key=yBs76VurxRiBwtDHrrF2JJlLgVrcv3
awx_official=true

Change firewall rules

If you are running a firewall, Masquerade And allow http and https services. This is very important, please don’t skip it. If you change the port in the previous manifest file, please also allow it in the firewall.

sudo firewall-cmd --zone=public --add-masquerade --permanent
sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --reload

Execute the script

Run and install Ansible Playbook to deploy AWX docker container. Run the ansible-playbook command, followed by the option -i, which tells it which manifest file to use. The name of the script file is install.yml.

sudo ansible-playbook -i inventory install.yml

The above command will take some time to complete. After completion, you can use the docker ps command to check the created Docker container and its status.

$ docker ps

CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                  NAMES       
feb21b5e6c62        ansible/awx:13.0.0   "tini -- /usr/bin/la…"   3 minutes ago       Up 24 seconds       8052/tcp               awx_task    
423d8c6e4550        ansible/awx:13.0.0   "tini -- /bin/sh -c …"   3 minutes ago       Up 22 seconds       0.0.0.0:80->8052/tcp   awx_web     
11d2953d4f67        postgres:10          "docker-entrypoint.s…"   3 minutes ago       Up 22 seconds       5432/tcp               awx_postgres
724d5c4f8162        redis                "docker-entrypoint.s…"   3 minutes ago       Up 25 seconds       6379/tcp               awx_redis   

Step 4: Access the AWX web interface

To access the AWX Web console, please point your browser to Ansible’s AWX server IP: http://your-server-ip-address. If you change the port configuration in the manifest file, point your browser to http://your-server-ip-address:

Welcome to the login page, as shown in the figure below.

Install and configure Ansible AWX on CentOS 8

After opening, enter administrator Username and admin_password The password you specified in the manifest file. After successful authentication, you will enter the AWX management console. There is a lot of work to be done, and we will only introduce a few of them. On the left side of the dashboard is the navigation menu where you can quickly navigate to projects, inventory, job templates, and jobs.

Install and configure Ansible AWX on CentOS 8

Step 5: Create users and groups

AWX provides a default user admin, which you can use to perform tests. However, if you need another user, you can create another user.

To add a new user other than the default administrator, click the “Users” tab on the left menu. A new page will be displayed where you can add new users. Click green + Icon, and then fill in the details of the new user to be added.

Install and configure Ansible AWX on CentOS 8

When finished, click “save“.

Install and configure Ansible AWX on CentOS 8

The same goes for creating a new team. Click “Team“Tab can be found in the left menu. A new page will appear where you can add a new team. Click the green + Icon and fill in the details of the new team to be added.

Install and configure Ansible AWX on CentOS 8

When finished, click “save“.

Install and configure Ansible AWX on CentOS 8

Step 6: Create an organization

An organization is a logical collection of users, teams, projects, and inventory. It is the highest-level object in the AWX object hierarchy. In the left navigation bar, click organization icon. You will find that the default organization has been automatically created and is available to all users of Ansible AWX.

Install and configure Ansible AWX on CentOS 8

It can be used as is or edited as needed. Let’s edit it by changing its name and adding users, permissions, etc.

Install and configure Ansible AWX on CentOS 8

Click “User number“Tab and add a new user. I have not created a new user before, so the admin default user appears. But you can create other users as shared Step 5.

Install and configure Ansible AWX on CentOS 8

If you have other users, they will be populated

Install and configure Ansible AWX on CentOS 8

Clicking on a user will display all users associated with this organization. A user is someone who can access Ansible AWX with associated roles and credentials. Adding a user to the organization will only add him as a member. Authority Label, as shown in the following example:

Install and configure Ansible AWX on CentOS 8

Step 7: Create a certificate

In order for Ansible to log in and perform tasks, it will need credentials to access the remote host. AWX provides us with this feature. Click “certificate“And click the green + Add new server credentials.

Install and configure Ansible AWX on CentOS 8

Fill in the name, description, organization, user name, password and credential type, the list is very long. We will select the computer because in this example we intend to configure a single host. If you prefer a key-based authentication mechanism, you can add an ssh key. Also add privilege escalation under sudo.

Install and configure Ansible AWX on CentOS 8

Click “saveOnce completed.

Install and configure Ansible AWX on CentOS 8

Step 8: Create a new list and add it to the organization

The inventory is a collection of hosts managed by Ansible. The checklist is assigned to the organization, and the authority to start the script against the checklist is controlled at the user and/or team level.

To create and view existing inventory, click stock The icon in the left navigation bar. To create a new inventory, click Add (+) Button and select “Inventory” from the drop-down menu list.

Install and configure Ansible AWX on CentOS 8

Enter the name and organization to which this list will belong. Click “save“So that other tags can be activated.

Install and configure Ansible AWX on CentOS 8

For this example, we will add a host, but you know that you can create a group of one or more hosts, and you want to perform certain actions on them at the same time. Click “host“Tab and click + Add a new host.

Install and configure Ansible AWX on CentOS 8

On the new page that loads, add the IP or resolvable host name and description. We want to install Nginx In this example, the name on a given host is the intuitive name.

Install and configure Ansible AWX on CentOS 8

Click “save“After completion, new inventory should be created.

Install and configure Ansible AWX on CentOS 8

Group and host concept

Note that the inventory is divided into groups and hosts. A group may represent a specific environment (for example, “Data Center 1” or “Test Bed”), a server type (for example, “Web Server” or “Database Server”), or any other representation of your environment.

Step 9: Create a project

A project is a logical collection of Ansible playbooks represented in Ansible AWX. You can manage scripts and script directories in the following ways: manually place them under the “project base path” on the tower server, or put the scripts in the source code management (SCM) system supported by Ansible AWX, including Git, Subversion And Mercurial.

To create a new project, follow the same process as the rest of the processes you have seen so far. Click “Project“And click Add (+) Create a new project.

Install and configure Ansible AWX on CentOS 8

After you get there, fill in the details to suit your needs. On the source control manager (SCM) type, you can create a git repo containing all the scripts, or you can create a local folder on the server according to the suggestion when selecting “manual” under the SCM type. I prefer to add git repo in this example. Please note that if you have multiple organizations, we will still refer to the organization you choose.

Install and configure Ansible AWX on CentOS 8

Enter all the details and click “save“. The file created on the git repo (nginx.yml) has the following content:

---
- hosts: all
  gather_facts: true
  become: true
  become_user: root
  tasks:
    - apt:
        name: nginx
      when: ansible_os_family == "Debian"

The attached screenshot is as follows:

Install and configure Ansible AWX on CentOS 8

Step 10: Set up the template and start it

So far, we have done a lot of work, all that is left is to put everything into one template. The job template combines the Ansible playbook in the project with the settings required to start it. Click “Create new job templateTemplateThe “” tab on the left navigation menu. Click his green to add (+) Add a new template like any other template. When the window opens, just select the list, project, credentials and Playbook that we have configured in the previous step. Also give the template a name and an optional description.

Install and configure Ansible AWX on CentOS 8

When you are done, scroll down and click “save“. After saving, you can “emissionMake it work immediately.

Install and configure Ansible AWX on CentOS 8

After clicking Start, you will be redirected to “jobs“On the page, you will see it execute in real time and display the output.

Install and configure Ansible AWX on CentOS 8

If all goes well, the script should be successfully run by Ansible behind the scenes. All errors encountered along the way will be displayed on the right.

Install and configure Ansible AWX on CentOS 8

Log in to the server being tested and check whether nginx has been successfully installed

Install and configure Ansible AWX on CentOS 8

Surprisingly, the Ansible AWX installation is officially installed and running normally.

More information about Ansible Tower | AWX is available at RedHat Ansible Tower Quick Start Guide.

Ansible learning courses:


Ansible-hands-on-DevOps

Ansible-hands-on-DevOps

★★★★★
(13530)

$14.07

$117.24

In stock

Buy now

Install and configure Ansible AWX on CentOS 8Udemy.com


Ansible Advanced-Hands-on-DevOps

Ansible Advanced-Hands-on-DevOps

★★★★☆
(2811)

$14.07

$164.14

In stock

Buy now

Install and configure Ansible AWX on CentOS 8Udemy.com


Master DevOps with Docker, Kubernetes and Azure DevOps

Master DevOps with Docker, Kubernetes and Azure DevOps

★★★★☆
(1443)

$14.07

$164.14

In stock

Buy now

Install and configure Ansible AWX on CentOS 8Udemy.com


DevOps project: CI/CD with Jenkins Ansible Docker Kubernetes

DevOps project: CI/CD with Jenkins Ansible Docker Kubernetes

★★★★☆
(3109)

$14.07

$ 87.93

In stock

Buy now

Install and configure Ansible AWX on CentOS 8Udemy.com

in conclusion

Ansible can change the way you perform daily management tasks, and can offload a lot of manual work from your hands, and give you plenty of time to perform other tasks. Use this technology as an innovation engine to deliver your applications faster and win greater success.

Other exciting guides you might like include:

Use Ansible to manage users and groups on Linux

How to generate Linux user encrypted password for Ansible

Install Apache Tomcat 9 on Debian 10 using Ansible

How to install Ansible AWX on Debian 10 (Buster)

Set up Ansible AWX on Ubuntu Linux

Deploy a Kubernetes cluster using Ansible and Kubespray

To
You can download this article in PDF format via the link below to support us.

Download the guide in PDF format

turn off
To

To
To

Sidebar