question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Appendix A - Vagrant with VirtualBox within WSL2 to run ansible-for-devops VMs

See original GitHub issue

I 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:

  1. Install WSL2, and install Ubuntu in WSL2.
  2. Install VirtualBox (I’m running 6.1.x).
  3. 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 --version1
  4. 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.
  5. cd into one of the ansible-for-devops example directories (e.g. drupal).
  6. Edit the Vagrantfile and make sure to disable the default shared folder (add line config.vm.synced_folder '.', '/vagrant', disabled: true).2
  7. 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:open
  • Created 3 years ago
  • Reactions:5
  • Comments:30 (13 by maintainers)

github_iconTop GitHub Comments

25reactions
ozbosscommented, Apr 7, 2021

This took me some time to figure out, but here is my complete solution:

  1. Install WSL2, and install Ubuntu in WSL2.

  2. Install VirtualBox (I’m running 6.1.x).

  3. 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:

    export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
    export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"
    

    e. Restart shell f. vagrant --version

  4. Check if “bsdtar” is installed: bsdtar --version (to install on ubuntu: sudo apt install libarchive-tools)

  5. 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)

  6. Enable chmod (required for vagrant ssh, enables correct permissions for private key) a. Edit or create /etc/wsl.conf b. add:

    [automount]
    options = "metadata"
    

    c. Shutdown WSL from powershell: wsl --shutdown

  7. 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 Firewall

  8. SSH into vm: vagrant ssh (should not be asking for a password, otherwise check that the “private_key” (see vagrant ssh-config -> “IdentitiyFile”) has correct permissions of “-rw-------” / “chmod 600”, if not repeat step 6. and recreate vm)

8reactions
geerlingguycommented, Jun 24, 2020

I randomly get the following error about every third playbook run from within WSL2:

TASK [Install Node.js and npm.] ************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named ansible.module_utils
fatal: [192.168.55.55]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.55.55 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1593008691.439251-2336-205927529649911/AnsiballZ_yum.py\", line 104, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1593008691.439251-2336-205927529649911/AnsiballZ_yum.py\", line 96, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1593008691.439251-2336-205927529649911/AnsiballZ_yum.py\", line 39, in invoke_module\r\n    from ansible.module_utils import basic\r\nImportError: No module named ansible.module_utils\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

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:

npm ERR! shasum check failed for /tmp/npm-4183-1105ef61/registry.npmjs.org/winston/-/winston-0.8.3.tgz
npm ERR! Expected: 64b6abf4cd01adcaefd5009393b1d8e8bec19db0
npm ERR! Actual:   7654c0b56ea856b2ee6010ef593d9d189b239a87
npm ERR! From:     https://registry.npmjs.org/winston/-/winston-0.8.3.tgz

And then on the next run I got the warning:

TASK [Install Node.js and npm.] ************************************************
[WARNING]: sftp transfer mechanism failed on [192.168.55.55]. Use
ANSIBLE_DEBUG=1 to see detailed information
ok: [192.168.55.55]

Also getting the following for most Git operations (though sometimes they succeed?!):

TASK [Check out drush 8.x branch.] *********************************************
fatal: [172.16.88.8]: FAILED! =>

cmd:
/usr/bin/git clone --origin origin https://github.com/drush-ops/drush.git /opt/drush

msg:
Cloning into '/opt/drush'...
error: inflate: data stream error (incorrect data check)
fatal: pack has bad object at offset 322670: inflate returned -3
fatal: index-pack failed", "rc": 128, "stderr": "Cloning into '/opt/drush'...
error: inflate: data stream error (incorrect data check)
fatal: pack has bad object at offset 322670: inflate returned -3
fatal: index-pack failed

If anyone says Windows now has ‘as seamless of Linux integration as macOS’ I think I might slap them with a trout 🐟 .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found