流浪版本
Vagrant 2.2.10
主机操作系统
Windows 10(20045,2020年5月)
访客操作系统
Ubuntu 18.04(尝试过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
错误:
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 VM,Vagrant应该能够连接到它(而不是我得到
default: Warning: Connection refused. Retrying...
一遍又一遍,但我无法通过SSH连接)。
实际行为
WSL2中的流浪汉无法连接到刚刚启动的VM。
U9HRRBMV:/ mnt / c / Users / KeithJames / firewall-role-ak $服务ssh状态 * sshd正在运行
复制步骤
使用Ubuntu bash在Windows 10(2004)上安装WSL2
使用上面的Vagrantfile创建目录
在WSL2环境中下载并安装适用于Linux的Vagrant(无论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无法成功完成。任何错误输出应为 在上方可见。请更正这些错误,然后重试。