How to install Ansible with PIP, the Python package manager?
Today we’re going to talk about how to use the up-to-date version of Ansible in Linux and macOS using PIP. I’m Luca Berton and welcome to today’s episode of Ansible Pilot
How to install Ansible with PIP
Today we’re talking about How to install Ansible with PIP. PIP is the Python package manager and is going to take care of all the processes and manage the necessary dependency. It takes care of the download and installs process of packages directly from PyPI. PIP is designed to be OS-independent. It could be a solution for developers that always want the latest up-to-date release. The alternative approach is to use the Operating System specific Package Manager. For example for Linux yum, DNF, and apt and for macOS Homebrew. This second approach put more emphasis on stability so the latest release could be not available. So if you really need the latest release of Ansible I’d suggest you use PIP.
Demo install Ansible with PIP
Demo time! Let me Playbooknstrate to you how to install the latest of Ansible with PIP, the Python package manager.
code PIP user
- install-pip-user.sh
#!/bin/bash
python3 -m pip install --upgrade -user pip
python3 -m pip install --user ansible
install-pip-global.sh
code PIP global
- install-pip-global.sh
#!/bin/bash
python3 -m pip install --upgrade pip
python3 -m pip install ansible
- Execution
root@demo:/home/devops# python3 -m pip install --upgrade pip
Requirement already satisfied: pip in /usr/lib/python3/dist-packages (20.3.4)
Collecting pip
Downloading pip-22.1.2-py3-none-any.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 1.4 MB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.3.4
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-22.1.2
root@demo:/home/devops# python3 -m pip install ansible
Collecting ansible
Downloading ansible-6.1.0-py3-none-any.whl (40.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.5/40.5 MB 795.8 kB/s eta 0:00:00
Collecting ansible-core~=2.13.1
Downloading ansible_core-2.13.1-py3-none-any.whl (2.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 715.5 kB/s eta 0:00:00
Requirement already satisfied: cryptography in /usr/lib/python3/dist-packages (from ansible-core~=2.13.1->ansible) (3.3.2)
Requirement already satisfied: PyYAML>=5.1 in /usr/lib/python3/dist-packages (from ansible-core~=2.13.1->ansible) (5.3.1)
Collecting jinja2>=3.0.0
Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 595.7 kB/s eta 0:00:00
Requirement already satisfied: packaging in /usr/lib/python3/dist-packages (from ansible-core~=2.13.1->ansible) (20.9)
Collecting resolvelib<0.9.0,>=0.5.3
Downloading resolvelib-0.8.1-py2.py3-none-any.whl (16 kB)
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: resolvelib, MarkupSafe, jinja2, ansible-core, ansible
Attempting uninstall: MarkupSafe
Found existing installation: MarkupSafe 1.1.1
Uninstalling MarkupSafe-1.1.1:
Successfully uninstalled MarkupSafe-1.1.1
Attempting uninstall: jinja2
Found existing installation: Jinja2 2.11.3
Uninstalling Jinja2-2.11.3:
Successfully uninstalled Jinja2-2.11.3
Successfully installed MarkupSafe-2.1.1 ansible-6.1.0 ansible-core-2.13.1 jinja2-3.1.2 resolvelib-0.8.1
- Verification After the successful installation you could verify in the command line:
$ ansible --version
ansible [core 2.13.1]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
jinja version = 3.1.2
libyaml = True
Conclusion
Now you know how to install Ansible with PIP, the Python package manager. Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my Udemy 300+ Lessons Video Course.
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate