Vagrant版本
Vagrant 2.2.10
主机操作系统
Windows 10(200452020年5月(
访客操作系统
Ubuntu 18.04(试用16.04,20.04(
流浪文件
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
错误:
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.
预期行为
VirtualBox虚拟机应该启动,Vagrant应该能够连接到它(相反,我得到了
default: Warning: Connection refused. Retrying...
一遍又一遍,我无法通过SSH连接(。
实际行为
WSL2内部的Vagrant无法连接到它刚刚启动的VM。
U9HRRBMV:/mnt/c/Users/KeithJames/防火墙角色ak$service ssh状态*sshd正在运行
复制的步骤
在Windows 10(2004(上安装WSL2,使用Ubuntu bash
在中创建一个包含上述Vagrantfile的目录
在WSL2环境中下载并安装Vagrant for Linux(无论是否安装在Windows中(
运行流浪者
我也试过:
在WSL2中运行流浪ssh。
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ vagrant ssh
U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$
然后我尝试使用原始SSH:
U9HRRBMV:/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
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...
等待机器启动时超时。这意味着Vagrant无法在配置的("config.vm.boot_timeout"值(时间段。
如果您查看上面的内容,您应该能够看到Vagrant在试图连接到机器时有。这些错误通常都是很好的提示,说明可能出了什么问题。
如果您使用的是自定义框,请确保网络连接正确工作,您就可以连接到机器。这是常见的这些盒子中的网络设置不正确的问题。验证身份验证配置是否也正确设置,也
如果盒子似乎正确引导,您可能需要增加超时("config.vm.boot_timeout"(值。
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未能成功完成。任何错误输出都应上面可见。请修复这些错误,然后重试。
VirtualBox
VirtualBox Vagrant Machine
正如HashiCorp所说,您不应该在WSL上安装流浪者。您必须使用Windows中的流浪者.exe。https://www.vagrantup.com/docs/other/wsl
我可以通过以下操作在我的环境(Windows 10 Pro版本22H2、VirtualBox版本7.0.6(安装在Windows上(、Ubuntu 20.04.5 LTS(运行在WSL2中((上运行它:
- 执行上提供的说明https://blog.thenets.org/how-to-run-vagrant-on-wsl-2/
- 修改Windows Defender防火墙设置,如中所述https://github.com/microsoft/WSL/issues/4139#issuecomment-732665787
- 修改Windows Defender防火墙设置,如";修复问题";在里面https://thedatabaseme.de/2022/02/20/vagrant-up-running-vagrant-under-wsl2/
剩余问题:
Windows发出警告";Microsoft Defender防火墙使用的设置可能会使您的设备不安全">