无法在 Ansible 中没有 sudo 的情况下 ping 主机



与Ansible的第一天,我正在关注入门文档。

http://docs.ansible.com/intro_getting_started.html

我用一个主机创建了'/etc/ansible/hosts'文件。

命令sudo ansible all -m ping -vvvv工作正常。

当我丢下sudo时,我会得到:

02.my_first_host.com | FAILED => SSH Error: Permission denied (publickey,gssapi-with-mic,password).
    while connecting to xx.xx.xx.xx:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

这是/etc/ansible/hosts文件的权限问题吗?我将/etc/Ansible的所有权递归地更改为用户,没有运气。

您可以通过行为参数在库存文件中定义用户。但是-u和您一样,应该具有相同的结果。

可能没有使用您的私钥,因为您没有.ssh/config。(Wild Guess!)您可以通过--private-key明确地将通往密钥的路径通过,或者再次将其设置为库存或组/主机var中的行为参数。

通过库存:

[all:vars]
user=root
ansible_ssh_private_key_file=/path/to/file

通过group_vars,相对于您的剧本,另存为group_vars/all

...
user: root
ansible_ssh_private_key_file: /path/to/file
---

最新更新