Loading
Computer Terminal Window

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

Last Updated on 07/06/2020 by Grant Little

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

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

  1. Just wanted to say this was awesome! I use WSL for Jekyll (for blogging on GitHub pages) but 100% a Linux novice. I have dabbled with Ansible but usually in a VM. This is the best way I have found to install on WSL.

  2. I’m learning Ansible as a Networking student. I have Miniconda & Python packages installed for other courses on laptop & have setup virtual envs in Miniconda.
    I’m learning to use Linux when I can but only have a Win10 laptop, and use Docker to avoid VirtualBox/VMWare resource hungry.
    Can I/Should I do the same using Conda env (instead of Python venv)? If yes, I can start figuring how to set up Ansible through WSL2 in Docker Desktop.
    Thanks.

Leave a Reply

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