gpt4 book ai didi

ansible - Vagrant box 未设置在 WSL2 下运行

转载 作者:行者123 更新时间:2023-12-05 06:59:55 29 4
gpt4 key购买 nike

Vagrant 版

Vagrant 2.2.10

主机操作系统

Windows 10(20045,2020 年 5 月)

客户操作系统

Ubuntu 18.04(试用 16.04、20.04)

Vagrant 文件

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 中的 Vagrant 无法连接到它刚刚启动的 VM。

U9HRRBMV:/mnt/c/Users/KeithJames/firewall-role-ak$ 服务 ssh 状态* sshd 正在运行

重现步骤

  1. 使用 Ubuntu bash 在 Windows 10 (2004) 上安装 WSL2

  2. 创建一个包含上述 Vagrantfile 的目录

  3. 在WSL2环境下下载并安装Vagrant for Linux(不管是安装在Windows上)

  4. 运行 vagrant up

我也试过:

在 WSL2 中运行 vagrant 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 无法与内部的 guest 计算机通信配置的(“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 上安装 vagrant。您必须使用 Windows 中的 vagrant.exe。 https://www.vagrantup.com/docs/other/wsl

关于ansible - Vagrant box 未设置在 WSL2 下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64266970/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com