Install Ansible on CentOS / Red Hat / Ubuntu / Debian

How does Ansible work?

Ansible translates Ansible playbooks into commands that are run over SSH, which has several benefits when it comes to managing Unix-like environments:

  1. Most, if not all of the Unix-like machines you are administering will have SSH running by default.
  2. Relying on SSH means that no agent is required on the remote host.
  3. In most cases no additional software needs to be installed as Ansible requires Python 2.6 in order to operate. Most, if not all distributions of Linux have this version (or greater) installed by default.
  4. Ansible does not require a master node. It can be run from any host that has the Ansible package installed and sufficient SSH access.
  5. Although running Ansible in a cron job is possible, by default Ansible only runs when you tell it to.

Installing Python & python-pip

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

sudo dnf -y install python3
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 three 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 https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

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
===================================================================================================================================================
Installing:
 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.

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:

Method 3: Install Ansible on CentOS 8 / RHEL 8 from RedHat registration

First register your Redhat OS by subscription-manager command

 # subscription-manager register

it will ask for RedHat account username & password.

after successful registration you have to enable some repos given below:

# subscription-manager repos --enable satellite-tools-6.6-for-rhel-8-x86_64-rpms
Repository' satellite-tools-6.6-for-rhel-8-x86_64-rpms' is enabled for this system.

# subscription-manager repos --enable ansible-2.9-for-rhel-8-x86_64-rpms
Repository' ansible-2.9-for-rhel-8-x86_64-rpms' is enabled for this system.

To install Ansible on the RHEL 8 control node after registering with the Satellite server, run the command yum install ansible. This command installs six packages:

  1. Install Ansible from the Ansible repo:
    1. Ansible
  2. Install dependencies:
    1. sshpass
    2. Python3-markupsafe
    3. Python3-jinja2
    4. Python3-babel
  3. Install weak dependency:
    1. Python3-jmespath

After the installation, run the ansible --version command to check the version of Ansible installed.

For Ubuntu / debian based systems, you can install Ansible from the PPA :

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

Now you can check Ansible version :

it will show ansible version & default python version also.

Thank you for reading this article.

Was this helpful?

0 / 0

Leave a Reply 4

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


zovptor

zovptor

This is very interesting, You’re a very skilled blogger. I have joined your feed and look forward to seeking more of your great post. Also, I have shared your website in my social networks!

Ray Malone

Ray Malone

I ran the steps for Ubuntu. All seems to complete successfully except the last step to install ansible. I received the error “E: Unable to locate package ansible”

Can you help me figure this out?

zortilonrel

zortilonrel

I think this site has some really excellent info for everyone :D. “America is not merely a nation but a nation of nations.” by Lyndon B. Johnson.

zortilo nrel

zortilo nrel

It is truly a great and helpful piece of information. I¦m happy that you just shared this helpful info with us. Please stay us up to date like this. Thanks for sharing.