10

我已经下载了一个 git repo 并运行了 vagrant,但我收到了这个错误消息

The following settings don't exist: inventory_file

我已经为 osx 山狮安装了 virtual box 和 vagrant 和 ansible。

但我什么都做不了。

当我跑步时,我也ansible all -m ping -vvvv得到

<192.168.0.62> ESTABLISH CONNECTION FOR USER: Grant
<192.168.0.62> EXEC ['ssh', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Users/Grant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=22', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', '192.168.0.62', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-1379790346.17-244145524385544 && chmod a+rx $HOME/.ansible/tmp/ansible-1379790346.17-244145524385544 && echo $HOME/.ansible/tmp/ansible-1379790346.17-244145524385544'"]
192.168.0.62 | FAILED => SSH encountered an unknown error. The output was:
OpenSSH_5.9p1, OpenSSL 0.9.8y 5 Feb 2013
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/Users/Grant/.ansible/cp/ansible-ssh-192.168.0.62-22-Grant" does not exist
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.0.62 [192.168.0.62] port 22.
debug2: fd 3 setting O_NONBLOCK
debug1: connect to address 192.168.0.62 port 22: Operation timed out
ssh: connect to host 192.168.0.62 port 22: Operation timed out

任何关于正在发生的事情的想法将不胜感激:)

4

4 回答 4

11

对于该inventory_file问题,请尝试更改Vagrantfile要使用的inventory_path。我认为这种微妙的变化发生在 Vagrant 1.3.x 中。如果你不想修改Vagrantfile尝试使用 Vagrant 1.2.x。

运行时:

ansible all -m ping -vvvv

这将使用您当前的用户并在默认位置查找 Ansible 主机清单 ( /etc/ansible/hosts)。

为了让它与 Vagrant 定义的 VM 一起工作,您需要使用vagrant用户,指定在连接期间使用的 SSH 密钥并指定主机清单的位置,例如

ansible all \
  -i provisioning/inventory # <-- or wherever the inventory is \ 
  -m ping \
  -u vagrant \
  --private-key ~/.vagrant.d/insecure_private_key
于 2013-09-22T11:26:46.383 回答
3

它已经在整个块中重复使用~/.vagrant.d/insecure_private_key,但我发现它实际上是.vagrant/machines/default/virtualbox/private_key在使用的路径中Vagrantfile。他们可能将密钥生成更改为每台机器,而不是用户范围,但文档尚未反映这一点。

因此,对于整个命令,它将是:

ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --private-key=.vagrant/machines/default/virtualbox/private_key -u vagrant playbook.yml

vagrant ssh-config您可以通过运行并查找值来检查是否是其中一个IdentityFile

于 2015-02-04T11:29:15.340 回答
0

您可以将它们放入 ansible 配置文件,而不是每次都传递 inventory_file、private_key 和 ssh_user。在这里查看我更详细的答案:https ://stackoverflow.com/a/25316963/502457

于 2014-08-14T20:28:42.343 回答
0
$ ansible all -i inventory -m ping -u vagrant --private-key ~/.vagrant.d/insecure_private_key
ansible_ssh_private_key_file=/Users/dxiao/.vagrant.d/insecure_private_key | FAILED => 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
ansible_ssh_user=vagrant | FAILED => 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
testserver | success >> {
    "changed": false,
    "ping": "pong"
}

$ cat inventory
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=/Users/dxiao/.vagrant.d/insecure_private_key

有用。

于 2015-01-08T05:54:33.703 回答