Vagrant, Ansible and VirtualBox on WSL
I’ve finally succedded in installing and deploying three CentOS virtual boxes using Vagrant and Ansible from within WSL (Windows Subsystem for Linux) and behind a proxy!
Here I will highlight the main stumbling parts and the commands and/or environment variable to run and/or set in order to overcome one hurdle after the other in getting thigs running smoothly.
Warning: This is not an howto or a tutorial. If you tinkering with Vagrant and Ansible, I assume you know how to install and setup the whole environment…
Requirements:
- For WSL to work, make sure the VT support is enabled in your BIOS
- Vagrant: latest
- Vagrant plugins:
- vagrant-proxyconf needed for running behind proxy
- virtualbox_WSL2 needed for running under WSL
- vagrant-vbguest automatically installs the host’s VirtualBox Guest Additions
- Ansible: latest
- Virtualbox: latest
Ansible Environment:
Multi-Machine Vagrant Environments: This Vagrantfile will create 3 Centos VM’s to simulate Ansible control machine and 2 target hosts.
- host1
- host2
- ansible-host
WSL Environment Setup
Bash environment:
|
|
VAGRANT Environment Setup
VirtualBox settings needed for Vagrant
|
|
Plugin Installation
Install (some plugins might need to be installed as user, not root to work):
|
|
git setup
|
|
Install requirements
|
|
Files included:
- ansible.cfg
- inventory
- bootstrap-node.sh
- ansible-install.yaml
- playbook.yaml
- inventory.yaml
Connecting the dots:
Before you run vagrant up, make sure that you updated the Vagrantfile to your desired configuration. Specifically use the box that are available from https://atlas.hashicorp.com/boxes/.
Once you are done:
-
vagrant up Wait a few minutes to finish the build. Once done. You can try to ssh to your ansible-host vm. You can verify this by using “vagrant status”
-
vagrant ssh ansible-host once you are login to your ansible-host vm, you can now verify if the other vm are reachable.
Full code is available here: https://github.com/xserty/ansible-labs, but don’t forget to setup the environment!
Example code was taken from https://github.com/mikecali/ansible-labs-101 under GNU General Public License v3.0.