How to install Ansible on Centos 7

The following procedure will give you steps to proceed with ansible on Centos 7.

This article will not describe how to create a VM depending on Hypervisor (VMware, Virtuel Box, Hyper-V …). You need to choose your own virtualization solution for installing your Virtual Machine.

Before installing Ansible, you need to have a VM fully installed and updated with Centos 7.

Make sure the latest Python version is installed on your system. As root, do as follow:

$ sudo yum install dnf

$ sudo dnf update

$ sudo dnf install python3

$ sudo python3 -V

If python is installed properly, you should have the following ouput:

$ sudo python3 -V
Python 3.6.8

Make sure pip (Python Package Manager) is installed on your system:

$ sudo dnf install python3-pip

Usually python3-pip package is installed at the same time you install the lastest version of python:

$ sudo dnf install python3
Last metadata expiration check: 0:00:24 ago on Tue 01 Oct 2019 07:29:47 PM CEST.
Dependencies resolved.
Package                                                          Arch                                                 Version                                                      Repository                                          Size
python3                                                          x86_64                                               3.6.8-10.el7                                                 base                                                69 k
Installing dependencies:
python3-libs                                                     x86_64                                               3.6.8-10.el7                                                 base                                               7.0 M
python3-pip                                                      noarch                                               9.0.3-5.el7                                                  base                                               1.8 M
python3-setuptools                                               noarch                                               39.2.0-10.el7                                                base                                               629 k
Transaction Summary
Install  4 Packages
Total download size: 9.4 M
Installed size: 48 M
Is this ok [y/N]:

Now that all requirement are met, let’s start with Ansible installation. logon to your VM as regular user and perform the following steps:

$ pip3 install ansible –user

You should have the following output:

[user@ansible ~]$ pip3 install ansible –user
Collecting ansible
Downloading (14.4MB)
100% |████████████████████████████████| 14.4MB 119kB/s
Collecting jinja2 (from ansible)
Downloading (124kB)
100% |████████████████████████████████| 133kB 3.3MB/s
Requirement already satisfied: PyYAML in /usr/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: cryptography in /usr/lib64/python3.6/site-packages (from ansible)
Collecting MarkupSafe>=0.23 (from jinja2->ansible)
Requirement already satisfied: idna>=2.1 in /usr/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: six>=1.4.1 in /usr/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in /usr/lib64/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: pycparser in /usr/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.7->cryptography->ansible)
Installing collected packages: MarkupSafe, jinja2, ansible
Running install for ansible … done
Successfully installed MarkupSafe-1.1.1 ansible-2.8.5 jinja2-2.10.1

Once installed, you can verify that installation was done correctly by checking the version of Ansible package:

$ ansible –version

You should have the following output:

[user@ansible ~]$ ansible –version
ansible 2.8.5
config file = None
configured module search path = [‘/home/nathan/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/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)]

You are done !

Comments are closed.