Ansible in a Python virtual env


I use an Ubuntu machine running within WSL2 (see also WSL2 on Windows 10)

Install requirements and

sudo apt install -y python3-venv

Create your venv

mkdir ~/virtualenvs
cd ~/virtualenvs
python3 -m venv ansible

restart Ubuntu running in WSL2.

Using a venv

Install ansible in your venv

source ~/virtualenvs/ansible/bin/activate
pip3 install wheel
pip3 install ansible

ansible --version

Use deactivate to leave the python virtual env

(ansible) [email protected]_NAME:~/virtualenvs$ deactivate
[email protected]_NAME:~/virtualenvs$

You can see the actual functionality of the venv with which python and in your $PATH variable. Python is now used from an alternate locaton bin folder and this is also placed in your path.

(ansible) [email protected]_NAME:~/virtualenvs$ which python
(ansible) [email protected]_NAME:~/virtualenvs$ echo $PATH | tr ":" "\n" | grep virtualenv
comments powered by Disqus