使用 Ansible 的第一天,我正在关注入(inject)门文档。
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 的所有权递归地更改为我的用户,但没有成功。
最佳答案
您可以通过 behavioral parameters 在 list 文件中定义用户。但是-u
,就像你所做的那样,应该有相同的结果。
Ansible 可能没有使用您的私钥,因为您没有 .ssh/config。 (疯狂猜测!)您可以使用 --private-key
显式传递 key 路径,或者再次将其设置为 list 或组/主机变量中的行为参数。
通过库存:
[all:vars]
user=root
ansible_ssh_private_key_file=/path/to/file
通过 group_vars,保存为与您的 playbook 相关的 group_vars/all
:
...
user: root
ansible_ssh_private_key_file: /path/to/file
---
关于ansible - 在 Ansible 中如果没有 sudo 则无法 ping 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30031776/