Loading
Computer Terminal Window

Installing Ansible on Windows Subsystem for Linux (WSL) using Ubuntu

First of all you will need to have Ubuntu installed under WSL. If you haven’t already done that, then I suggest you check out my post on Installing Ubuntu 20.04 on WSL

You will then need to make sure you have python3 installed. This is generally installed by default, but you can check it by doing the following:-

python3 -V

I generally recommend installing Ansible using “pip3” which generally means you get access to the very latest version of Ansible rather than the pre-packaged versions controlled by the distributions, as these can sometimes be a fair bit behind the latest stable release.

To avoid conflicts with packages installed by your distribution I generally find it is best to use the python virtualenv. This creates an isolated location for all python packages to be installed without interfering with the host system too much.

To do this:-

sudo apt install -y python3-venv

Once installed we then need to create a directory to store our virtual environments and then create a specific environment for ansible

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

Now that this has been done, we need to tell python to use this virtualenv. You will need to restart the WSL application (e.g. Ubuntu 20.04)

source ~/virtualenvs/ansible/bin/activate

Once loaded the command prompt will indicate which virtualenv is in use by adding an (<environment>) to the front of the command prompt. In our case the environment is called (ansible)

To avoid issues when installing Ansible with “wheel” not being available. Run the following

pip3 install wheel

We can now go ahead and install Ansible itself

pip3 install ansible

You should now be able to test Ansible is installed

ansible --version

One thought on “Installing Ansible on Windows Subsystem for Linux (WSL) using Ubuntu

Leave a Reply

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

%d bloggers like this: