• Category: Ansible

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.

main

Windows Setup

  1. Install Virtual Box
  2. Install Ubuntu WSL
  3. Reboot computer

WSL Setup

  1. Run Ubuntu from the start menu and upgrade all packages
    apt update && apt upgrade -y
  2. Reset the root password (I couldn't seem to get this to work with sudo)
     sudo passwd root
  3. Login in as root
    su -l root
  4. Install Ansible
    apt-add-repository ppa:ansible/ansible
    apt install ansible
  5. Install Python pip
    apt-get install -y python-pip libssl-dev
  6. Install Pip packages
    pip install molecule
    pip install python-vagrant
  7. Set ENV variable so vagrant knows its running in WSL
    export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
  8. Install Vagrant and plugins
    apt install vagrant
    vagrant plugin install vagrant-libvirt
  9. 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"
  10. 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"
  11. 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. 

error

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' ]"

workaround