Install Ansible, Molecule, Vagrant on Windows WSL
Ansible is a really cool and very popular config management (and a lot more!) tool but sadly the control plane only runs on Linux based systems. As primarily a Windows user I wanted to see if it would function in the “newish” WSL environment and after a lot of trial and error found that it works great! In this quick post I go over how to install Ansible for config management, Molecule to test roles, Vagrant to run the tests all while running on Windows WSL.
Windows Setup
- Install Virtual Box
- Install Ubuntu WSL
- Reboot computer
WSL Setup
-
Run Ubuntu from the start menu and upgrade all packages
sudo apt update && apt upgrade -y
-
Install Ansible
sudo apt-add-repository ppa:ansible/ansible sudo apt install ansible
-
Install Python pip
sudo apt-get install -y python-pip libssl-dev
-
Install Pip packages
sudo pip install molecule sudo pip install python-vagrant
-
Set ENV variable so vagrant knows its running in WSL
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
-
Install Vagrant and plugins
sudo apt install vagrant sudo vagrant plugin install vagrant-libvirt
-
In order for WSL to know where Virtual box is installed some additional paths need to be added
export PATH=$PATH:/mnt/c/Windows/System32 export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"
-
If you want to prevent the need to run the above EXPORT commands on every login add the following to the bottom of ~/.bashrc
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1" export PATH=$PATH:/mnt/c/Windows/System32 export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"
-
You are now ready to run Ansible and Molecule with WSL!
Molecule Gotchas
By default, Molecule uses the ubuntu/xenial64 box for test runs. During my initial testing I kept encountering an error like the one below.
After inspecting the /tmp/molecule/base-test/default/vagrant-instance.err log I found this.
Stderr: VBoxManage.exe: error: RawFile#0 failed to create the raw output file /usr/local/lib/python2.7/dist-packages/molecule/provisioner/ansible/playbooks/vagrant/ubuntu-xenial-16.04-cloudimg-console.log (VERR_PATH_NOT_FOUND)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
After some searching, I found the following workaround for molecule.yml and everything started to run correctly.
"customize [ 'modifyvm', :id, '--uartmode1', 'disconnected' ]"
Leave a comment