Ansible & Python Installation on to an Ubuntu Box

Rangaswamy P V
3 min readApr 27, 2020

--

Note:The lines starting with “$” are the unix commands that needs to be executed in the Ubuntu Box

Here we are going to see how to install Ansible on to a Ubuntu Box(16.04) will work for Ubuntu 18.x ,19.x and 20.x as well.

PreRequisites:

Make sure you have the right Python Version

Follow the steps below or simply download and execute the file ./py.sh from https://github.com/rangapv/ansible-install.git repo to upgrade the python version/new python installation and jump to the section Next Update the libraries as shown below for Ansible Install.

Just run the script “./py.sh” in the directory and it will prompt for the Python version to be installed and you may want to choose the 3.x.x version displayed in the prompt and it will install all the necessary libraries and binaries for both Python & pip.

$ ./py.sh

Then Check if the upgrade was successful with this command

$ python3 -V

So now you have python version 3 installed.

The following libraries are needed in case it asks for permission just type “y”

$ sudo apt-get install selinux-utils$ sudo apt-get install -y policycoreutils$ sudo apt-get install selinux-basics

Now we are needing to disable the SELinux status

$ sudo setenforce 0

To check if SELinux is disabled

$ sestatus

The output should say as :

selinux disabled

or

SELinux status: disabled

Bingo !

Back to Ansible Installs:

Execute the following command one after another for Ansible to be installed in the Ubuntu Box

$ sudo apt-get update$ sudo apt-get install software-properties-common$ sudo apt-get update$ sudo -H pip install ansible

Check if the Installation is successful…

$ansible --version

Sample output…

ansible 2.9.7
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/home/rangapv08/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.5.2 (default, Apr 16 2020, 17:47:17) [GCC 5.4.0 20160609]

To Check if Ansible works …

$ ansible -m ping localhost

Sample Output…

[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
“changed”: false,
“ping”: “pong”
}

You are all set to use Ansible now on Ubuntu!

If you have any issues, you can open an issue in the github repo page or alternatively contact me at rangapv@yahoo.com and you can also find me on X.com(twitter) @rangapv

--

--

Rangaswamy P V

Works on Devops in Startups, reach me @rangapv on twitter or email: rangapv@gmail.com