11/30/2021

Ansible Pip

Pip (recursive acronym for “Pip Installs Packages” or “Pip Installs Python“) is a cross-platform package manager for installing and managing Python packages (which can be found in the Python Package Index (PyPI)) that comes with Python 2 >=2.7.9 or Python 3 >=3.4 binaries that are downloaded from python.org.

Suggested Read:How to Install Latest Python 3.6 Version in Linux

Ansible Pip

Ansible Pip Upgrade

In this article, we will explain how to install PIP on mainstream Linux distributions.

  • Pip (recursive acronym for “Pip Installs Packages” or “Pip Installs Python“) is a cross-platform package manager for installing and managing Python packages (which can be found in the Python Package Index (PyPI)) that comes with Python 2 =2.7.9 or Python 3 =3.4 binaries that are downloaded from python.org.
  • By using this option, pip also installed the “yamllint” and “ansible-lint” tools that allow you to use Molecule to perform static code analysis of your role, ensuring it complies with Ansible coding standards.

Note: We will run all commands as the root user, if you are managing your system as a normal user, then use the sudo command to get root privileges or you can as well configure your system to run sudo command without entering a password, it’s possible. Try it out!

Install PIP in Linux Systems

To install pip in Linux, run the appropriate command for your distribution as follows:

Ansible Pipelining

Installing Ansible. Prerequisites; Selecting an Ansible artifact and version to install; Installing and upgrading Ansible with pip; Installing Ansible on specific operating systems; Installing and running the devel branch from source; Confirming your installation; Finding tarballs of tagged releases; Adding Ansible command shell completion. Pip install kolla-ansible. If not using a virtual environment: sudo pip3 install kolla-ansible. Create the /etc/kolla directory. Sudo mkdir -p /etc/kolla sudo chown.

Install PIP On Debian/Ubuntu

Install PIP On CentOS and RHEL

Ansible

Unluckily, pip is not packaged in official software repositories of CentOS/RHEL. So you need to enable the EPEL repository and then install it like this.

Ansible Pipe Command

Install PIP on Fedora

Install PIP on Arch Linux

Install PIP on openSUSE

How to Use PIP in Linux Systems

Ansible Pipe

To install, uninstall or search new packages, use these commands.

To see a list of all commands type:

Sample Output

You may also like to read these following related articles about Python.

In this article, we showed you how to install PIP on mainstream Linux distributions. To ask any questions relating to this topic, please take advantage of the feedback form below.

Note

This module is part of ansible-base and included in all Ansibleinstallations. In most cases, you can use the short module namepip even without specifying the collections: keyword.Despite that, we recommend you use the FQCN for easy linking to the moduledocumentation and to avoid conflicting with other collections that may havethe same module name.

  • Manage Python library dependencies. To use this module, one of the following keys is required: name or requirements.

The below requirements are needed on the host that executes this module.

  • pip

  • virtualenv

  • setuptools

ParameterChoices/DefaultsComments
chdir
path
cd into this directory before running the command
editable
boolean
    Choices:
  • no
  • yes
executable
added in 1.3 of ansible.builtin
The explicit executable or pathname for the pip executable, if different from the Ansible Python interpreter. For example pip3.3, if there are both Python 2.7 and 3.3 installations in the system and you want to run pip for the Python 3.3 installation.
Mutually exclusive with virtualenv (added in 2.1).
The setuptools package must be installed for both the Ansible Python interpreter and for the version of Python specified by this option.
extra_args
string
Extra arguments passed to pip.
name
list / elements=string
The name of a Python library to install or the url(bzr+,hg+,git+,svn+) of the remote package.
This can be a list (since 2.2) and contain version specifiers (since 2.7).
requirements
string
The path to a pip requirements file, which should be local to the remote system. File can be specified as a relative path if using the chdir option.
state
string
    Choices:
  • absent
  • forcereinstall
  • latest
The state of module
The 'forcereinstall' option is only available in Ansible 2.1 and above.
umask
string
The system umask to apply before installing the pip package. This is useful, for example, when installing on systems that have a very restrictive umask by default (e.g., '0077') and you want to pip install packages which are to be used by all users. Note that this requires you to specify desired umask mode as an octal string, (e.g., '0022').
version
string
The version number to install of the Python library specified in the name parameter.
virtualenv
path
An optional path to a virtualenv directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv.
virtualenv_command
path
Default:
'virtualenv'
The command or a pathname to the command to create the virtual environment with. For example pyvenv, virtualenv, virtualenv2, ~/bin/virtualenv, /usr/local/bin/virtualenv.
virtualenv_python
string
The Python executable used for creating the virtual environment. For example python3.5, python2.7. When not specified, the Python version used to run the ansible module is used. This parameter should not be used when virtualenv_command is using pyvenv or the -m venv module.
virtualenv_site_packages
boolean
    Choices:
  • no
  • yes
Whether the virtual environment will inherit packages from the global site-packages directory. Note that if this setting is changed on an already existing virtual environment it will not have any effect, the environment must be deleted and newly created.

Ansible pipefail

Note

  • The virtualenv (http://www.virtualenv.org/) must be installed on the remote host if the virtualenv parameter is specified and the virtualenv needs to be created.

  • Although it executes using the Ansible Python interpreter, the pip module shells out to run the actual pip command, so it can use any pip version you specify with executable. By default, it uses the pip version for the Ansible Python interpreter. For example, pip3 on python 3, and pip2 or pip on python 2.

  • The interpreter used by Ansible (see ansible_python_interpreter) requires the setuptools package, regardless of the version of pip set with the executable option.

Common return values are documented here, the following are the fields unique to this module:

KeyReturnedDescription
cmd
string
success
Sample:
namesuccess
list of python modules targetted by pip

['ansible', 'six']
requirements
string
success, if a requirements file was provided
Sample:
versionsuccess, if a name and version were provided
Version of the package specified in 'name'

2.5.1
virtualenv
string
success, if a virtualenv path was provided
Sample:

Authors¶

  • Matt Wright (@mattupstate)