Vagrant, Ansible, and VirtualBox on WSL (Windows Subsystem for Linux)
How To
This guide covers how to get Vagrant and Ansible running together on Windows 10 using WSL (Windows Subsystem for Linux), such that they use VirtualBox on the Windows host.
Action Steps Install Git on Windows
- Go to https://git-scm.com/download/win.
- Download 64-bit Git for Windows.
- Run the .exe file once it finishes downloading.
Install VirtualBox on Windows
- Go to https://www.virtualbox.org/wiki/Downloads.
- Click on Windows Hosts link.
- Run the .exe file once it finishes downloading.
- (Optional) Download and install the Extension Pack.
Install WSL on Windows 10 Pro
- Open PowerShell as Administrator and run: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows Subsystem-Linux
Action Steps 2. Restart Windows.
Install Ubuntu 18.04 LTS from Windows Store
- Go to https://www.microsoft.com/en-us/p/ubuntu-1804lts/9n9tngvndl3q#activetab=pivot:overviewtab.
- Click the Get / Install option.
- Run Ubuntu 18.04 from the Start menu.
- Create a username and password when prompted.
- Close the Ubuntu terminal window.
Configure VS Code to use WSL in the Integrated Terminal
- Press Ctrl+Shift+P to open the Command Palette.
- Type: Terminal: Select Default Shell
- Select: WSL Bash
Install Python and PIP in WSL
- Press Ctrl+` in VS Code to open the Integrated Terminal.
- Type the following in the terminal: cd ~ sudo apt-get update sudo apt-get dist-upgrade -y sudo apt-get install python mkdir downloads cd downloads curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py --user
- Add the local bin directory to PATH: echo 'export PATH="${PATH}:/home/jeff/.local/bin"' >> ~/.bashrc Note: Replace jeff with your actual username.
Install Ansible in WSL
- Type the following in the terminal: pip install ansible --user
Action Steps Install Vagrant in WSL
- Go to https://www.vagrantup.com/downloads.html.
- Right-click and copy the link for the 64-bit Debian package.
- Type the following in the terminal: wget https://releases.hashicorp.com/vagrant/2.1.5/vagrant_2.1.5_x86_64.deb dpkg -i vagrant_2.1.5_x86_64.deb Note: Replace the link and the .deb package name with the one you actually copied.
Configure Vagrant in WSL to Use VirtualBox on Windows
- Type the following in the terminal: echo 'export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"' >> ~/.bashrc echo 'export PATH="${PATH}:/mnt/c/Program Files/Oracle/VirtualBox"' >> ~/.bashrc source ~/.bashrc Clone my Demo GitHub Repository
- Type the following in the terminal: cd /mnt/c/Users/jeff/Desktop/ git clone https://github.com/JeffReeves/WSL-Ansible-VagrantVirtualBox.git cd WSL-Ansible-Vagrant-VirtualBox Start the VM in VirtualBox using Vagrant
- Type the following in the terminal: vagrant up Verify VM was Provisioned
- Go to http://127.0.0.1:8080/ in a browser.
- Verify that a demo page is displayed. Stop and Destroy the VM
- Type the following in the terminal: vagrant halt vagrant destroy