我如何用ansible ping我的流浪盒?

时间:2016-09-10 17:52:23

标签: ssh vagrant virtual-machine ansible

我跟随tutorial显示如何设置流浪者vm来练习使用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
}

我做错了什么?

谢谢:)

2 个答案:

答案 0 :(得分:1)

您可能还希望将您的ansible管理节点放入流浪者vm本身。这个tutorial很好地展示了它。

答案 1 :(得分:0)

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