How it works..

The easiest way to install Ansible is by using the package manager specific to our Linux distribution. We just need to make sure that we have enabled the required repositories to install the latest version of Ansible. In both Ubuntu and CentOS, we need to enable extra repositories that provide the latest version for Ansible. In CentOS, we need to install and enable the Extra Packages for Enterprise Linux Repository (EPEL repo), which provides extra software packages and has the latest Ansible packages for CentOS. 

Using this method, we will install Ansible and all the requisite system packages needed to run the Ansible modules. In both Ubuntu and CentOS, this method will also install Python 2 and run Ansible using Python 2. We can validate the fact that Ansible is installed and which version is used by running the following command:

$ ansible --version
ansible 2.9
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Also, we can check that Ansible is working as expected by trying to connect to the local machine using the ping module as shown:

$ ansible -m ping localhost

localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}

Using this method, we can see that it has the following issues:

  • It uses Python 2 as the execution environment, but we want to use Python 3.
  • It updates the Python packages installed on the system, which might not be desirable.
  • It doesn't provide us with the granularity needed in order to select which version of Ansible to use. Using this method, we will always install the latest version of Ansible, which might not be what we need.