Vagrant box not getting set up running under WSL2

Vagrant version:

Vagrant 2.2.10

Host OS:

Windows 10 (20045, May 2020)

Guest OS:

Ubuntu 18.04 (tried with 16.04, 20.04)

Vagrantfile:

Vagrant.configure(“2”) do |config|
config.vm.box = “ubuntu/trusty64”

config.vm.synced_folder “.”, “/vagrant”, disabled: true

config.vm.provider “virtualbox” do |vb|
vb.memory = “4024”
vb.cpus = “1”
end

config.vm.provision “ansible” do |ansible|
ansible.become = true
ansible.verbose = “v”
ansible.playbook = “roles/firewall.yml”
ansible.galaxy_roles_path = “./roles”
end
end

Error:

/mnt/c/Users/KeithJames/firewall-role-ak$ vagrant up --provisionBringing machine ‘default’ up with ‘virtualbox’ provider… ==> default: Checking if box ‘ubuntu/trusty64’ version ‘20190514.0.0’ is up to date… ==> default: Running provisioner: ansible… default: Running ansible-playbook… PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_ROLES_PATH=‘/mnt/c/Users/KeithJames/firewall-role-ak/roles’ ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS=‘-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s’ ansible-playbook --connection=ssh --timeout=30 --limit=“default” --inventory-file=/mnt/c/Users/KeithJames/firewall-role-ak/.vagrant/provisioners/ansible/inventory --become -v roles/firewall.yml Using /etc/ansible/ansible.cfg as config file PLAY [all] ********************************************************************* TASK [Gathering Facts] ********************************************************* fatal: [default]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port 2222: Connection refused”, “unreachable”: true} PLAY RECAP ********************************************************************* default : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0 Ansible failed to complete successfully. Any error output should be visible above. Please fix these errors and try again.

Expected behavior:

The VirtualBox VM should be started, Vagrant should be able to connect to it (instead I get

default: Warning: Connection refused. Retrying…

over and over, and I can’t connect via SSH).

Actual behavior:

Vagrant inside WSL2 can’t connect to the VM it just started.

/mnt/c/Users/KeithJames/firewall-role-ak$ service ssh status* sshd is running

Steps to reproduce:

  1. Install WSL2 on Windows 10 (2004), with Ubuntu bash

  2. Create a directory with the above Vagrantfile in it

  3. Download and install Vagrant for Linux in the WSL2 environment (regardless of it being installed in Windows)

  4. Run vagrant up

I also tried:

Run vagrant ssh in WSL2.

/mnt/c/Users/KeithJames/firewall-role-ak$ vagrant ssh
/mnt/c/Users/KeithJames/firewall-role-ak$

Then I tried using raw SSH:

/mnt/c/Users/KeithJames/firewall-role-ak$ ssh -p 2222 vagrant@127.0.0.1
ssh: connect to host 127.0.0.1 port 2222: Connection refused

So this is a connectivity issue with your vagrant VM.
If you fix that the ansible playbook that vagrant calls will also start to work.

Thanks Dick