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:-
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)
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
6 thoughts on “Installing Ansible on Windows Subsystem for Linux (WSL) using Ubuntu”
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.
Thanks for the feedback
This worked well for me thanks!
worked on my wsl2. thank you
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.