vagrant ansible以下设置不存在:inventory_file

时间:2013-09-21 21:11:45

标签: osx-mountain-lion vagrant ansible

我已经删除了一个git repo并且运行了但是我收到了这个错误消息

The following settings don't exist: inventory_file

我已经为osx mountain lion安装了虚拟盒子和流浪者和安塞尔。

但我无法得到任何工作。

当我运行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 个答案:

答案 0 :(得分:11)

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

运行时:

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

答案 1 :(得分: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值来检查是否是其中之一。

答案 2 :(得分:0)

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

答案 3 :(得分: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

它有效。