You want to install Ansible on CentOS 8 / RHEL 8 Linux?. Ansible is the leading Open Source configuration management system. It makes it easy for administrators and operations teams to control thousands of servers from central machine without installing agents on them.

Ansible is the simplest to use and manage when compared to other configuration management systems such as Puppet, Chef and Salt. It is easy to install, learn, and use. The only dependency required on the remote server is SSH service and Python.

Install and Configure Ansible on CentOS 8 / RHEL 8 using the steps below.

Step 1: Install Python on RHEL 8 / CentOS 8

Install and Set your default Python on RHEL 8 using the guide below.

How to Install Python 3 / Python 2.7 on RHEL 8

Once it has been installed, proceed to install Pip which is a Python package manager used to install Ansible.

If you’re using Python3, install python3-pip package.

sudo dnf -y install python3-pip
sudo pip3 install --upgrade pip

For Python2 users you have to install python2-pip

sudo dnf -y install python2-pip
sudo pip2 install --upgrade pip

Step 2: Install Ansible on RHEL 8 / CentOS 8

There are two methods from which you can install Ansible on CentOS 8 / RHEL 8.

Method 1: Install Ansible on CentOS 8 / RHEL 8 from EPEL

Add EPEL repository to your CentOS 8 / RHEL 8 system.

sudo dnf -y install

Then Enable EPEL playground repository and install Ansible on CentOS 8 / RHEL 8 from it.

sudo dnf install  --enablerepo epel-playground  ansible

This will default to using Python 3, so some Python 3 packages are installed.

Dependencies resolved.
 Package                            Arch                     Version                                       Repository                         Size
 ansible                            noarch                   2.8.5-2.epel8.playground                      epel-playground                    15 M
Installing dependencies:
 python3-jmespath                   noarch                   0.9.0-11.el8                                  AppStream                          45 k
 python3-pyasn1                     noarch                   0.3.7-6.el8                                   AppStream                         126 k
 python3-bcrypt                     x86_64                   3.1.6-2.epel8.playground.1                    epel-playground                    44 k
 python3-pynacl                     x86_64                   1.3.0-5.epel8.playground                      epel-playground                   100 k
 sshpass                            x86_64                   1.06-9.epel8.playground                       epel-playground                    27 k
 libsodium                          x86_64                   1.0.18-2.el8                                  epel                              162 k
Installing weak dependencies:
 python3-paramiko                   noarch                   2.4.3-1.epel8.playground                      epel-playground                   289 k

Transaction Summary
Install  8 Packages

Total download size: 15 M
Installed size: 81 M
Is this ok [y/N]: y

Check the version of Ansible installed on your CentOS 8 / RHEL 8 system.

$ ansible --version
ansible 2.8.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/cloud-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Jul  1 2019, 16:43:04) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]

Method 2: Install Ansible on CentOS 8 / RHEL 8 using pip

Once you have Pip installed, you can use it to get Ansible installed in your CentOS 8 / RHEL 8 machine.

$ pip3 install ansible --user

For Python2 pip, use:

$ pip2 install ansible --user

You can see Ansible installed using the following command:

$ ansible --version
ansible 2.7.5
config file = None
configured module search path = ['/home/jmutai/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jmutai/.local/lib/python3.6/site-packages/ansible
executable location = /home/jmutai/.local/bin/ansible
python version = 3.6.6 (default, Oct 16 2018, 01:53:53) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]

Step 3: Testing Ansible on CentOS 8 / RHEL 8 Linux

To test Ansible, you should have OpenSSH service running on the remote server.

$ sudo systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-12-29 20:17:11 EAT; 39min ago
Docs: man:sshd(8)
Main PID: 820 (sshd)
Tasks: 1 (limit: 11510)
Memory: 4.6M
CGroup: /system.slice/sshd.service
└─820 /usr/sbin/sshd -D [email protected],[email protected],aes256-ctr,aes256-cbc,[email protected],aes128->
Dec 29 20:17:11 rhel8.local systemd[1]: Starting OpenSSH server daemon…
Dec 29 20:17:11 rhel8.local sshd[820]: Server listening on port 22.
Dec 29 20:17:11 rhel8.local sshd[820]: Server listening on :: port 22.
Dec 29 20:17:11 rhel8.local systemd[1]: Started OpenSSH server daemon.
Dec 29 20:19:03 rhel8.local sshd[1499]: Accepted publickey for jmutai from port 35902 ssh2: RSA SHA256:b/8AoYgbThoBYPcFh7CetJuGY/Tl7s4fi>
Dec 29 20:19:03 rhel8.local sshd[1499]: pam_unix(sshd:session): session opened for user jmutai by (uid=0)

Create Ansible inventory file, default is /etc/ansible/hosts

I like creating inventory file in my working directory.

$ vim hosts

Copy the IP address of your remote server(s) to manage and add to Ansible inventory file.

$ echo "" > hosts

You can also create a group of hosts like below:




Generate SSH key and copy it to remote servers.

$ ssh-keygen
$ ssh-copy-id [email protected]

Use ping module to test ansible:

$ ansible  -i hosts -m ping | SUCCESS => {
"changed": false,
"ping": "pong"

The -i option is used to provide path to inventory file. You should get the same output for hosts group name.

$ ansible  -i hosts  web -m ping | SUCCESS => {
"changed": false,
"ping": "pong"

For commands that need sudo, pass the option --ask-become-pass. This will ask for privilege escalation password. This may require installation of the sshpass program.

$ ansible  -i hosts  web -m command -a "sudo yum install vim"  --ask-become-pass
.... | CHANGED | rc=0 >>
 Updating Subscription Management repositories.
 Updating Subscription Management repositories.
 Last metadata expiration check: 0:52:23 ago on Sat 29 Dec 2018 08:28:46 PM EAT.
 Package vim-enhanced-2:8.0.1763-7.el8.x86_64 is already installed.
 Dependencies resolved.
 Nothing to do.

You now have Ansible installed on RHEL 8 / CentOS 8 server or Workstation. You can learn more on using Ansible to Manage your servers from Official Ansible documentation.

Courses to checkout:

More on Ansible:

Install Ansible AWX on CentOS 7 With Nginx Proxy and Let’s Encrypt

How To Install and Configure Ansible Tower on CentOS 7 / RHEL 7/8

How To Install Ansible AWX on Ubuntu 18.04 / Debian 10

Ansible Vault Cheat Sheet / Reference guide

How to automate simple repetitive tasks using Ansible

How To Install speedtest-cli on Ubuntu / CentOS / Debian using Ansible

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here