Install Ansible in Ubuntu , Red Hat and CentOS

Summary

In this post we will learn how to install the Ansible on Ubuntu, CentOS and RHEL . In the world of IT automation tools, Ansible name is famous among system admins and developers.

What is Ansible?

The Ansible is a popular automation tool which is widely used for configuration management, orchestration, application deployment, server or container provisioning and much more. The Ansible has cross-platform support which means you can automate the things in Linux/Unix like Operating system and Windows.

We can easily Automate through Ansible in both Physical and Cloud environments. In some cases, it is also used as Infrastructure As Code and also along with other IaC (Infrastructure As Code ). Now in modern time, it is one of the favorite tool among the DevOps engineers.

Features of Ansible

We tried to place some basic features of Ansible here so that in first step everything should look simple and not confused .

1. Ansible is agentless and use SSH to connect with client machine.
2. Ansible configuration files uses the YAML format.
3. Ansible runs with its module library and orchestrate the multiple nodes exist in network.
4. Ansible knows about the host address information through its inventory file.

NOTE: Here, we are describing installation of anisible in 3 different section. Hence, select the section as per your Operating system and best suited for you.

Install Ansible On Debian Based And Red Hat based Linux.

In this section we will install the Ansible through pip, yum and dnf commands on Red Hat, CentOS and Fedora.

Ubuntu is one of the most popular Debian based Linux. The same method you can also use in Debian or other Debian based Linux.

Similarly, CentOS and Fedora are Red Hat based Linux Operating System.

Install Ansible with pip on Ubuntu, CentOS, RHEL (Red Hat)

I personally like to go with pip installation method because we have to create complete Ansible file hierarchy from scratch.

(A) First install pip into your system. Read our previous post on – How to install pip on CentOS / RHEL / Ubuntu / Debian, where you will find installing pip in various Operating System versions.

(B) Installing ansible with pip command.

On CentOS / RHEL / Ubuntu / Debian , use below command to install Ansible via pip.

sudo pip install ansible

Install Ansible on Ubuntu, Debian (apt / apt-get)

To install latest Ansible on Ubuntu system, use the below given command.

In Ubuntu 24.04 LTS, 20.04 LTS, 18.04 LTS and 16.04 LTS

sudo apt install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible

In Ubuntu 14.04 LTS or below

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

After installation, the /etc/ansible will be created and have two files i.e anisible.cfg and hosts .
Given below is reference from our system.

sharad@ubuntu:~$ ls -l /etc/ansible/
total 16
-rw-r--r-- 1 root root 8629 Jun 26 05:55 ansible.cfg
-rw-r--r-- 1 root root  965 Jun 26 05:55 hosts
sharad@ubuntu:~$

Install Ansible on CentOS / RHEL (yum / dnf)

To install Ansible on CentOS/RHEL , first you have to install EPEL repo into your system.

1. For CentOS 7 / RHEL 7 : Install EPEL repo on CentOS 7 and RHEL 7
2. For CentOS 6.x, 5.x / RHEL 6.x, 5.x : Install EPEL repo in CentOS 5.x , 6.x / RHEL 5.x, 6.x / Scientific Linux

Once you install the EPEL repo, you only have to hit the command –

sudo yum install ansible

After installation, you will see 2 files and 1 directory inside /etc/ansible .

See given below reference from our system .

[root@localhost ~]# ls -lhrt /etc/ansible/
total 16K
drwxr-xr-x 2 root root 6 Jun 25 17:11 roles
-rw-r--r-- 1 root root 965 Jun 25 17:11 hosts
-rw-r--r-- 1 root root 8.5K Jun 25 17:11 ansible.cfg
[root@localhost ~]#

Install Ansible on RHEL 8

Enable Ansible Engine Repository on RHEL 8

sudo subscription-manager repos --enable ansible-2.9-for-rhel-8-x86_64-rpms
sudo yum install ansible

Install Ansible on RHEL 7

Enable Ansible Engine Repository on RHEL 7

sudo subscription-manager repos --enable rhel-7-server-ansible-2.9-rpms
sudo yum install ansible

FAQ

Here, in this section we will cover frequently asked question which you may be thinking about.

In this post, we have seen hosts file. What is it ?

Answer : This is Ansible inventory file. by default, it comes with examples hence suggest to take the backup and create your own new hosts file inside /etc/ansible.

In this post, we have found also found ansible.cfg file. What it do ?

Answer : It is comprised of ansible variables . Hence, we suggest you to read the commented and uncommented ansible variables written in this file.

In CentOS / RHEL ansible installation, what this roles directory do ?

Answer: By defaulr this roles directory is empty . But here, we can define the ansible role. You have to read our upcoming ansible tutorials where we will also write about ansible roles and playbooks.

Conclusion

In this article we have seen that either of method to install the Ansible it won’t affect its functionality. Whereas, when you install Ansible through pip you will get all ansible commands in system but no directory structure like on doing installation through apt and yum commands.

For beginner and deep learner, we would recommend to install Ansible through pip and start practicing. It will help to understand the basics of Ansible directory structure from scratch.

Read Some More Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.