How to install Ansible with PIP in Ubuntu

Ansible is an IT automation tool. It can configure systems, deploy software, and orchestrate advanced IT tasks. In this tutorial we will see how to install Ansible with pip on Ubuntu 20.04 LTS.

Prerequisite for following this tutorial
  1. Control Node : VM having Ubuntu 18.04 LTS or above.

Lets install Ansible on Control Node with below steps.

Create user ansible


sudo useradd ansible

Add user ansible to sudoers file


sudo visudo

Add below entry at the end of /etc/sudoers


ansible     ALL=(ALL) NOPASSWD:ALL

Switch to ansible user, create ansible directory and change permissions


sudo su - ansible
mkdir /home/ansible;
cd /home/ansible;
sudo chown -R ansible:ansible /home/ansible/;

Install pip, if it is not installed already


curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --user

Check pip version


pip --version

If you are getting pip version than switch to step Install Ansible with pip, else follow below steps to add /home/ansible/.local/bin in the bash_profile


vi .bash_profile

Add "export PATH="$PATH:/home/ansible/.local/bin" in .bash_profile and activate bash_profile with below command and check pip version


source ~/.bash_profile
pip --version

Install Ansible with pip


pip install --user ansible

Verify Ansible installation


ansible --version

Output


ansible 2.9.9
config file = None
configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/ansible/.local/lib/python3.8/site-packages/ansible
executable location = /home/ansible/.local/bin/ansible
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]

If you are getting any error while following this tutorial, please post errors in comments, we will try to resolve those as soon as possible.

Next > Setting up Control and Managed Nodes

Categories: Linux