我怎样才能用ansible ping我的流浪者盒子?

How can I ping my vagrant box with ansible?

我正在关注 tutorial 展示如何设置 vagrant 虚拟机以练习使用 ansible。

我有以下目录结构、文件和配置:

➜  trusty64 tree
.
├── Vagrantfile
├── ansible
│   ├── hosts
│   ├── playbooks
│   └── roles
└── ansible.cfg

3 directories, 3 files
➜  trusty64 cat ansible/hosts
[vagrantboxes]
vagrant ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222

[vagrantboxes:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
➜  trusty64 cat ansible.cfg
[defaults]
host_key_checking = False
hostfile = ./ansible/hosts
roles_path = ./ansible/roles
➜  trusty64 vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/max/Desktop/vagrantboxes/trusty64/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

但是当我尝试 ping 我的虚拟机时它不起作用:

➜  trusty64 ansible all -m ping
vagrant | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}
➜  trusty64 ansible all -m ping -u vagrant
vagrant | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}

我做错了什么?

谢谢:)

Vagrant 更改第一个 VM 上的不安全密钥 运行。
ansible_ssh_private_key_file 更改为实际密钥 vagrant ssh-config:

ansible_ssh_private_key_file=/Users/max/Desktop/vagrantboxes/trusty64/.vagrant/machines/default/virtualbox/private_key

您可能还想将您的 ansible 管理节点放入 vagrant 虚拟机本身。这个tutorial很好地展示了它。