Running Ansible on Windows 10 WSL

Some years ago Microsoft announced the Windows Subsystem for Linux (WSL), which gave Windows 10 users the ability to run a Linux distro directly from their Windows install without the need for a VM.

I remember being somewhat dismissive and thinking to myself “why would anybody want to do that”. Fast forward a few years, and after spending many hours trying to get various Python packages to run under Windows, and having to deploy and maintain VMs to run tools like Ansible, I’ve seen the light.

This is a quick start no frills guide to getting Ubuntu installed and running, along with Ansible, on WSL.

Installing Ubuntu

  1. Enable Windows Subsystem for Linux under Turn Windows features on or off in the Control Panel
  2. Reboot (I love you, Windows)
  3. Open the Microsoft Store, find and install Ubuntu
  4. Find Ubuntu in the Start Menu, and run it

You will now find yourself in a bash shell running Ubuntu.

Updating Ubuntu

We can then do the usual update and upgrade

  1. sudo apt-get update && sudo apt-get upgrade

Installing Python and Ansible

Finally we need to install the pre-reqs and Ansible itself.

  1. sudo apt-get -y install python-pip python-dev libffi-dev libssl-dev
  2. pip install ansible --user

This will install Ansible in the users context (This is done to avoid permission issues with Pip that are specific to WSL)

Finally we update the $PATH to include ~/.local/bin where Ansible will live.

  1. echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
  2. source .bashrc

That should be it, we now have a working Ansible install without the need to run a VM!

md@lap-md:~$ ansible --version
ansible 2.8.0
  config file = None
  configured module search path = [u'/home/md/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/md/.local/lib/python2.7/site-packages/ansible
  executable location = /home/md/.local/bin/ansible
  python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]

If you enjoyed this post consider sharing it on , , , or , and .