Installing and Upgrading Ansible with *pip

Alex Duncan
Clarusway
Published in
3 min readJul 3, 2021

--

Installation

You can install Ansible on many systems with pip. Pip is the main Python package manager.

Prerequisites for installing pip:

If pip is not already have been installed on your system, then you must execute upcoming commands to install all package into your system.

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

Install Ansible with pip package:

After passing the installation of pip software , you can install Ansible.

$ python -m pip install --user ansible

If you will be in need of using the paramiko connection plugin or modules that require paramiko , install the necessary module:

$ python -m pip install --user paramiko

If you would like to install Ansible globally, run the following commands:

$ sudo python get-pip.py
$ sudo python -m pip install ansible

Use pip with sudo command in order to implement global changes to the system. Since pip does not coordinate with system package managers, it could make changes to your system that leaves it in an inconsistent or non-functioning state. This is particularly true for macOS. Installing with — user is recommended unless you understand fully the implications of modifying global files on the system.

Older versions of pip default to http://pypi.python.org/simple, which no longer works. Please make sure you have the latest version of pip before installing Ansible. If you have an older version of pip installed, you can upgrade by following pip’s upgrade instructions.

Installing Ansible in a virtual environment with pip:

Ansible can also be installed inside a new or existing virtualenv :

$ python -m virtualenv ansible  # Create a virtualenv if one does not already exist
$ source ansible/bin/activate # Activate the virtual environment
$ python -m pip install ansible

Upgrading Ansible with pip:

Upgrading from 2.9 or earlier to 2.10.

Starting in version 2.10, Ansible is made of two packages. When you upgrade from version 2.9 and older to version 2.10 or later, you need to uninstall the old Ansible version (2.9 or earlier) before upgrading. If you do not uninstall the older version of Ansible, you will see the following message, and no change will be performed.

Cannot install ansible-base with a pre-existing ansible==2.x installation.

Installing ansible-base with ansible-2.9 or older currently installed with
pip is known to cause problems. Please uninstall ansible and install the new
version:

pip uninstall ansible
pip install ansible-base

...

As explained by the message, to upgrade you must first remove the version of Ansible installed and then install it to the latest version.

$ pip uninstall ansible
$ pip install ansible

Upgrading from Ansible 3 or ansible-core 2.10

ansible-base only exists for version 2.10 and in Ansible 3. In 2.11 and later, the package is called ansible-core. Before installing ansible-core or Ansible 4, you must uninstall ansible-base if you have installed Ansible 3 or ansible-base 2.10.

To upgrade to ansible-core :

pip uninstall ansible-base
pip install ansible-core

To upgrade to Ansible 4:

pip uninstall ansible-base
pip install ansible

Installing Ansible on specific operating systems :

Follow these instructions to install the Ansible community package on a variety of operating systems.

Installing Ansible on RHEL, CentOS, or Fedora

On Fedora:

$ sudo dnf install ansible

On RHEL:

$ sudo yum install ansible

On CentOS:

$ sudo yum install epel-release
$ sudo yum install ansible

Installing Ansible on Ubuntu :

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible

Installing Ansible on Debian :

deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
$ sudo apt update
$ sudo apt install ansible

Wrap

I clarified some of the installation methods for the Ansible tool.

Hopefully, this overview has helped you better understand the terminology that is used for the installation of Ansible software.

If you found this helpful please share it on your favorite social media so other people can find it, too.

If that’s interesting for you, read and follow me on Medium.

https://clarusway.referral-factory.com/sW5XCt/join?j=10826&sfmc_sub=2678253&l=1485_HTML&u=106547&mid=546000854&jb=1

References:

https://docs.ansible.com/

--

--

Alex Duncan
Clarusway

Human, AWS/DevOps Expert, Writer, Reader, Researcher, Traveler