【问题标题】:Ansible can't ping my vagrant box with the vagrant insecure public keyAnsible 无法使用 vagrant 不安全的公钥 ping 我的 vagrant box
【发布时间】:2018-05-08 07:39:57
【问题描述】:

我在 osx 上将 Ansible 2.4.1.0 和 Vagrant 2.0.1 与 VirtualBox 一起使用,虽然我的 vagrant box 的配置可以在 ansible 上正常工作,但当我尝试 ping 时出现无法访问的错误:

➜  ansible all -m ping
vagrant_django | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", 
    "unreachable": true
}

针对类似问题提供的解决方案对我不起作用(例如将 vagrant insecure pub 密钥添加到我的 ansible 配置中)。我只是无法让它与 vagrant 不安全的公钥一起使用。

Fwiw,这是我的 ansible.cfg 文件:

[defaults]
host_key_checking = False
inventory = ./ansible/hosts
roles_path = ./ansible/roles
private_key_file = ~/.vagrant.d/insecure_private_key

这是我的 ansible/hosts 文件(ansible 清单):

[vagrantboxes]
vagrant_vm ansible_ssh_user=vagrant ansible_ssh_host=192.168.10.100 ansible_ssh_port=22 ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key

做了工作的是使用我自己的 SSH 公钥。当我将它添加到我的 vagrant box 上的 authorized_keys 时,我可以进行 ansible ping:

➜  ansible all -m ping       
vagrant_django | SUCCESS => {
    "changed": false, 
    "failed": false, 
    "ping": "pong"
}

我也无法通过 ssh 连接,所以这似乎是根本问题。通过将我自己的 pub 密钥添加到 authorized_hosts 中的 vagrant 框中来解决这个问题。

我很想知道为什么它不适用于 vagrant insecure 密钥。有人知道吗?

PS:澄清一下,虽然根本原因类似于this other question,但症状和上下文是不同的。我可以为我的盒子提供 ansible,但无法对它进行 ansible ping 操作。这证明了另一个问题恕我直言。

【问题讨论】:

标签: vagrant ansible ansible-inventory


【解决方案1】:

我很想知道为什么它不适用于 vagrant insecure 密钥。有人知道吗?

因为 Vagrant 不安全密钥仅用于与盒子的初始连接。默认情况下,Vagrant 将其替换为新生成的密钥,您可以在项目目录下的 .vagrant/machines/<machine_name>/virtualbox/private_key 中找到该密钥。

如果您在 Vagrantfile 中使用 Ansible 供应器,您还可以在 .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory 中找到自动生成的 Ansible 清单,因此您无需创建自己的。

【讨论】:

  • 谢谢!这确实是我错过的信息。我需要做的就是在我的 ansible.cfg 中包含自动生成的清单。也在这里的文档中找到了它,我起初忽略了它:vagrantup.com/docs/provisioning/ansible_intro.html
  • 我可以自己找出根本原因:'vagrant ssh-config'
猜你喜欢
  • 1970-01-01
  • 2015-04-12
  • 2015-09-14
  • 2018-11-18
  • 1970-01-01
  • 2017-08-05
  • 1970-01-01
  • 2015-09-23
  • 2016-07-16
相关资源
最近更新 更多