gpt4 book ai didi

Vagrant Ansible 配置 SSH 错误

转载 作者:行者123 更新时间:2023-12-04 12:20:43 25 4
gpt4 key购买 nike

我正在尝试做一些 Vagrant/Ansible 的东西,但从一开始就遇到了问题。这是我的 Vagrant 文件:

# -*- mode: ruby -*-
# vi: set ft=ruby :

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

config.vm.network "private_network", ip: "192.168.6.66"

config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end

config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
end
end

site.yml 只是
---
- name: Bring up server with MySQL, Nginx, and PHP-FPM
hosts: all
remote_user: root

roles:
- common

和 common/tasks/main.yml 是
---
- name: Update apt
apt: update_cache=yes

做的时候 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' is up to date...
==> default: Setting the name of the VM: ansible-provision_default_1412793587231_72507
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 2200 (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:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Checking for host entries
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/bram/Projects/Brammm/ansible-provision
==> default: Running provisioner: ansible...

PLAY [Bring up server with MySQL, Nginx, and PHP-FPM] *************************

GATHERING FACTS ***************************************************************
fatal: [default] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue

TASK: [common | Update apt] ***************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/bram/site.retry

default : ok=0 changed=0 unreachable=1 failed=0

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

如果我查看 .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory,我会看到以下内容:
default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200

我希望那里的 IP 与 private_network 中设置的相同?我已经盯着这个看了一个多小时了,我做错了什么吗?我有一种感觉,IP 设置不正确或什么的。我可以 ping 192.168.6.66 .

最佳答案

这里的问题是你的site.yml覆盖 ansible 将用于 root 的远程用户。但是,您不为其提供私钥,也不提供密码。

所以,我修复它的方式是设置 ansible_ssh_user到“vagrant”,因为它是默认的已知用户,并且 ansible 的行为与 vagrant ssh 相同如果 remote_user 未被覆盖。并设置sudo是的,因为“Vagrant ”用户是 sudoer,但不是 su。

# -*- mode: ruby -*-
# vi: set ft=ruby :

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

config.vm.network "private_network", ip: "192.168.6.66"

config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end

config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
ansible.extra_vars = { ansible_ssh_user: 'vagrant' }
ansible.sudo = true
#ansible.verbose = 'vvvv'
end
end

请参阅“为什么 ANSIble 供应商连接为错误的用户?”科 Ansible Provisioning of Vagrant Documentation

关于Vagrant Ansible 配置 SSH 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26264288/

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