Run Multiple Ansible Versions using Python 3 Virtual Environments

#Introduction

In this tutorial, How to Run Multiple Ansible Versions using Python 3 Virtual Environments. You can install multiple versions for Ansible

The benefits of using a virtual environment run Multiple Ansible Versions

  • Each project its isolated environment and modules
  • The base system is not affected
  • Does not require root access as virtual environments
Run Multiple Ansible Versions using Python 3 Virtual Environments

Install Python 3

CentOS 7

sudo yum -y install epel-release
sudo yum -y install python36 python36-pip

Ubuntu

Check the python version

python3 --version

If python is not installed by default, you can install it

sudo apt install python3.9 python3.9-venv

check the python version.

python3 -V

The output terminal is as below:

vagrant@devopsroles:~$ python3 -V
Python 3.9.5

Create Virtual Environments

First, we will need to create a folder that we’ll use to store the virtual environments. You do not create inside your project folder.

mkdir ~/python-environment

For example, I create two environments for different versions of Ansible using venv modules

cd ~/python-environment
python3.9 -m venv ansible2.7.0
python3.9 -m venv ansible2.8.0

The output terminal as below

Run Multiple Ansible Versions using Python 3 Virtual Environments

Activate an environment ansible version 2.7.0

source ansible2.7.0/bin/activate

Use pip install ansible 2.7.0

pip install --upgrade pip setuptools
pip install ansible==2.7.0
ansible --version

The output terminal as below

Run Multiple Ansible Versions using Python 3 Virtual Environments

List of Python packages that have been installed in this environment

pip list

deactivate the environment

deactivate

The output terminal as below

Run Multiple Ansible Versions using Python 3 Virtual Environments

Set up the second environment for ansible version 2.8.0

cd ~/python-environment
source ansible2.8.0/bin/activate
pip install --upgrade pip setuptools
pip install ansible==2.8.0
ansible --version
pip list
deactivate

You have the environments set up and use pip to install any packages without risk the base system packages.

Conclusion

You have Run Multiple Ansible Versions using Python 3 Virtual Environments. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

1 thought on “Run Multiple Ansible Versions using Python 3 Virtual Environments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.