Skip to content

Instantly share code, notes, and snippets.

@jeanlouisferey
Last active April 15, 2021 12:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanlouisferey/d61a3a487d4766a6fc6322a69e9e4542 to your computer and use it in GitHub Desktop.
Save jeanlouisferey/d61a3a487d4766a6fc6322a69e9e4542 to your computer and use it in GitHub Desktop.
How to use virtualenv to switch easily between multiple version of Ansible on Ubuntu

How to use virtualenv to switch easily between multiple version of Ansible

As root (sudo) get pip:

1- Install some dependencies:

   apt install build-essential libssl-dev libffi-dev python-dev

2- Install pip:

   wget https://bootstrap.pypa.io/get-pip.py
   python get-pip.py

As yourself:

3- Install virtualenv:

sudo pip install virtualenv

4- Install virtualenvwrapper

sudo pip install virtualenvwrapper
export WORKON_HOME=~/Envs
$ source /usr/local/bin/virtualenvwrapper.sh

5- Create a virtualenv for Ansible lastest version

mkvirtualenv ansible_latest
pip install ansible

6- Verify Ansible version with ansible --version

ansible 2.3.2.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

7- switch to your standard environment and create another virtualenv for Ansible 2.1.6.0

mkvirtualenv ansible_stable-2.1
pip install ansible==2.1.6.0

8- Verify Ansible version with ansible --version

ansible 2.1.6.0
  config file = 
  configured module search path = Default w/o overrides

PS: How to switch between different environments:

lsvirtualenv List all of the environments

workon Environment_Name Switch to Environment_Name

deactivate Switch to your standard environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment