How to Install Ansible Automation Tool on CentOS/RHEL 8

Ansible is a free and opensource automation tool that allows system administrators to configure and control hundreds of nodes from a central server without the need of installing any agents on the nodes.

It relies on the SSH protocol to communicate with the remote nodes. Compared to other management tools such as Puppet and Chef, Ansible comes out as the favorite due to its ease of use, and installation.

In this tutorial, you will learn how to install and configure the Ansible automation tool on RHEL/CentOS 8 Linux distribution.

IMPORTANT: For CentOS 8, ansible was traditionally distributed via EPEL repository, but there’s no official package yet, but it is being worked on. Therefore, we are using standard PIP (the Python package manager) to install Ansible on CentOS 8.

On RHEL 8, enable the official Red Hat repository, for the corresponding Ansible version that you want to install as shown in this article. DO NOT USE PIP ON RHEL 8!.

Step 1: Installing Python3

Usually, RHEL 8 and CentOS 8 will come with Python3 already installed by default. However, If for whatever reason Python3 is not installed, install it using the following dnf commands. Make sure you must log in as normal user with Sudo privileges.

# su - ravisaive
$ sudo dnf update
$ sudo dnf install python3
Install Python3 on RHEL and CentOS 8
Install Python3 on RHEL and CentOS 8

To verify that indeed you have python3 installed, run the command.

$ python3 -V
Verify Python Version
Verify Python Version

Step 2: Installing PIP – The Python Package Installer

Pip is a Python’s package manager, which is also comes preinstalled, but again, in case Pip is missing on your system, install it using the command.

$ sudo dnf install python3-pip
Install PIP on CentOS and RHEL 8
Install PIP on CentOS and RHEL 8

Step 3: Installing the Ansible Automation Tool

With all the prerequisites met, install ansible by running the command on CentOS 8.

# pip3 install ansible --user
Install Ansible in CentOS and RHEL 8
Install Ansible in CentOS and RHEL 8

On RHEL 8, enable the Ansible Engine repository to install corresponding Ansible version as shown,

# subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms
# dnf -y install ansible

To check the version of Ansible, run.

# ansible --version
Check Ansible Installation
Check Ansible Installation

Perfect! As you can see, the version of Ansible installed is Ansible 2.8.5.

Step 4: Testing the Ansible Automation Tool

To test ansible, first ensure that ssh is up and running.

$ sudo systemctl status sshd
Check SSH Status in CentOS and RHEL 8
Check SSH Status in CentOS and RHEL 8

Next, we need to create the hosts file in the /etc/ansible directory to define host machines.

$ sudo mkdir /etc/ansible  
$ cd /etc/ansible
$ sudo touch hosts

The hosts the file will be the inventory where you will have all your remote nodes.

Now open hosts file with your favorite editor and define the remote node as shown.

[web]
192.168.0.104

Next, generate SSH keys from which we will copy the public key to the remote node.

$ ssh-keygen
Generate SSH Keys for Ansible
Generate SSH Keys for Ansible

To copy the generated SSH key to the remote node run the command.

$ ssh-copy-id [email protected]
Copy SSH Key to Remote Linux
Copy SSH Key to Remote Linux

Now use Ansible to ping the remote node as shown.

$ ansible -i /etc/ansible/hosts web -m ping  
Ansible Ping Remote Host
Ansible Ping Remote Host

We have managed to successfully install and test Ansible on RHEL/CentOS 8 Linux distribution. If you have any questions, do share with us in the comments section below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

10 Comments

Leave a Reply
  1. Ansible for CentOS 8 is already present in the EPEL testing repository, so it can be installed in a same manner without messing with pip.

    Reply
    • Hey Atif, In the first step, we stated that the installation of Python3 is only necessary in the case, for some reason, Python3 is missing. This could be a result of someone messing up with the system.

      Reply
    • tecmint‘ in this case is the username of the user you are going to ssh as. Replace ‘tecmint‘ with your own username. The user must already have an account on the target system.

      Reply
  2. The correct way of installation on RHEL 8 is enabling the official Red Hat repository, for the corresponding Ansible version that you want to install. DO NOT USE PIP ON RHEL 8! Trying to install Ansible with pip is unsupported, will clutter your home directory and generally is terrible advice.

    # subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms
    # dnf -y install ansible
    

    That’s it for RHEL 8.

    For CentOS 8, ansible was traditionally distributed via EPEL. There’s no official package yet, but it is being worked on.

    Reply
    • @Radoslaw,

      Yes, you are correct, the correct way to install Ansible is from the official Red Hat repository. I will update the article and include official way of installing Ansible..

      Reply
  3. Hi James, thanks for your instructions. How can I find later the ansible.cfg file? I used to see the ansible folders created automatically under the /etc folder, what happened here?

    Cheers?

    Reply
    • Hey JF, indeed it’s true the ansible.cfg is not where you would expect as in the case of earlier versions such as CentOS 7 or RHEL 7. Even from the output, you can see that the file path to ansible.cfg is missing. Probably there could be a bug in the latest ansible version that’s not rendering everything as it should be.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.