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) user@HOST_NAME:~/virtualenvs$ deactivate

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) user@HOST_NAME:~/virtualenvs$ which python
(ansible) user@HOST_NAME:~/virtualenvs$ echo $PATH | tr ":" "\n" | grep virtualenv
comments powered by Disqus