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:
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ vagrant up --provision
Bringing 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.
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ service ssh status * sshd is running
Steps to reproduce
Install WSL2 on Windows 10 (2004), with Ubuntu bash
Create a directory with the above Vagrantfile in it
Download and install Vagrant for Linux in the WSL2 environment (regardless of it being installed in Windows)
Run vagrant up
I also tried:
Run vagrant ssh in WSL2.
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ vagrant ssh
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$
Then I tried using raw SSH:
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ ssh -p 2222 [email protected]
ssh: connect to host 127.0.0.1 port 2222: Connection refused
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' version '20190514.0.0' is up to date...
==> default: Setting the name of the VM: firewall-role-ak_default_1602247434343_82880
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
Timed out while waiting for the machine to boot. This means that Vagrant was unable to communicate with the guest machine within the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that Vagrant had when attempting to connect to the machine. These errors are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly working and you're able to connect to the machine. It is a common problem that networking isn't setup properly in these boxes. Verify that authentication configurations are also setup properly, as well.
If the box appears to be booting properly, you may want to increase the timeout ("config.vm.boot_timeout") value.
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ vagrant up --provision
Bringing 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.
As HashiCorp say, you shouldn't install vagrant on WSL. You have to use vagrant.exe from Windows. https://www.vagrantup.com/docs/other/wsl