Appendix A - Vagrant with VirtualBox within WSL2 to run ansible-for-devops VMs
See original GitHub issueI think it may finally work, but there are some caveats.
Following my work on Episode 14 of Ansible 101 (see #289), I found you have to do the following:
- Install WSL2, and install Ubuntu in WSL2.
- Install VirtualBox (I’m running 6.1.x).
- Inside WSL2/Ubuntu/Bash environment, install Vagrant:
a.
wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_linux_amd64.zip
b.unzip vagrant_2.2.9_linux_amd64.zip
c.sudo mv ./vagrant /usr/local/bin/vagrant
d.export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
e.vagrant --version
1 cd
into a/mnt/c
directory (like/mnt/c/Users/jgeerling/Downloads
) and clone or otherwise put the ansible-for-devops repository contents in there.cd
into one of the ansible-for-devops example directories (e.g.drupal
).- Edit the
Vagrantfile
and make sure to disable the default shared folder (add lineconfig.vm.synced_folder '.', '/vagrant', disabled: true
).2 - Run
vagrant up
from that directory.
1 It seems that every time I run a vagrant
command, the Bash terminal window is reverted to ‘raster’ fonts at a very tiny size, and I have to go into the window preferences to revert back to Consolas / 24 pt… Very weird.
2 There’s an issue for supporting shared folders within the WSL2 environment here. This might not be needed in the future.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:30 (13 by maintainers)
Top Results From Across the Web
Appendix A - Vagrant with VirtualBox within WSL2 to run ansible-for ...
Appendix A - Vagrant with VirtualBox within WSL2 to run ansible-for-devops VMs · Install WSL2, and install Ubuntu in WSL2. · Install VirtualBox...
Read more >How to run Vagrant + VirtualBox on WSL 2 (2021)
This tutorial will guide you to install Vagrant on Windows using WSL 2 (Windows Subsystem for Linux) with VirtualBox provider.
Read more >vagrant up – Running Vagrant under WSL2 - The Database Me
When now issueing vagrant up , Vagrant will create a VM in Virtualbox, spin it up and run the playbook on it (see...
Read more >Windows에서 WSL2/Vagrant/VBox로 Ansible 실습 - velog
개요 · 주요 참고 : Appendix A - Vagrant with VirtualBox within WSL2 to run ansible-for-devops VMs #291 · Vagrant and Windows Subsystem...
Read more >Course notes: Ansible on OSX - gr33nonline - WordPress.com
See Github issue: Appendix A – Vagrant with VirtualBox within WSL2 to run ansible-for-devops VMs #291 and Private network not getting set up ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This took me some time to figure out, but here is my complete solution:
Install WSL2, and install Ubuntu in WSL2.
Install VirtualBox (I’m running 6.1.x).
Inside WSL2/Ubuntu/Bash environment, install Vagrant: a.
wget https://releases.hashicorp.com/vagrant/2.2.15/vagrant_2.2.15_linux_amd64.zip
b.unzip vagrant_2.2.15_linux_amd64.zip
c.sudo mv ./vagrant /usr/local/bin/vagrant
d.nano ~/.profile
(~/.bash_profile
if exists) and add:e. Restart shell f.
vagrant --version
Check if “bsdtar” is installed:
bsdtar --version
(to install on ubuntu:sudo apt install libarchive-tools
)Fix vagrant for WSL2: a. Check this thread or this for a fix b. Otherwise install “virtualbox_WSL2” plugin:
vagrant plugin install virtualbox_WSL2
(source)Enable chmod (required for
vagrant ssh
, enables correct permissions for private key) a. Edit or create/etc/wsl.conf
b. add:c. Shutdown WSL from powershell:
wsl --shutdown
Create vm: a.
vagrant box add geerlingguy/centos7
b.vagrant init geerlingguy/centos7
c.vagrant up
d. Make sure to allow access for both private and public networks for VirtualBox when promted by Windows FirewallSSH into vm:
vagrant ssh
(should not be asking for a password, otherwise check that the “private_key” (seevagrant ssh-config
-> “IdentitiyFile”) has correct permissions of “-rw-------” / “chmod 600”, if not repeat step 6. and recreate vm)I randomly get the following error about every third playbook run from within WSL2:
It seems to maybe be yet another weird filesystem related issue? Or maybe networking between WSL2 and the Windows host? It never happens on the same task twice.
I’m also getting checksum errors, too, for example in NPM:
And then on the next run I got the warning:
Also getting the following for most Git operations (though sometimes they succeed?!):
If anyone says Windows now has ‘as seamless of Linux integration as macOS’ I think I might slap them with a trout 🐟 .