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
=============================================================================================================================================================================================================================================
Installing:
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 https://files.pythonhosted.org/packages/04/25/48fee5f8048360d9375e01846fcf395dda58242ed1f25a2106b6794452eb/ansible-2.8.5.tar.gz (14.4MB)
100% |████████████████████████████████| 14.4MB 119kB/s
Collecting jinja2 (from ansible)
Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl (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)
Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
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 setup.py 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 Off on How to install Ansible on Centos 7 Posted in Linux