Ansible 在 Vagrant 中使用的难点在于获取 ssh 登录需要的配置信息。
在默认 Vagrantfile
中我们找不到这些信息,此时需要通过 vagrant ssh-config
命令查看
1 | $ vagrant ssh-config |
啊,让我费解的 IdentityFile
文件终于露出来,关键就是这个文件。
接下来我们只需要配置 Ansible 的 hosts 文件,/etc/ansible/hosts
中添加,或者创建独立的 hosts
文件
1 | [vagrant] |
最后查看是否能正常连接
1 | $ ansible all -m command -a 'who' --inventory-file=hosts |
如果新建其他位置的 hosts
文件,需要 --inventory-file, -i
指定文件。
