在 Ansible 中没有 sudo 就无法 ping 通主机
Can't ping hosts without sudo in Ansible
使用 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 的所有权更改为我的用户,但运气不好。
您可以通过behavioral parameters在库存文件中定义用户。但是 -u
,就像你做的那样,应该有相同的结果。
可能是 Ansible 没有使用您的私钥,因为您没有 .ssh/config。 (大胆猜测!)您可以使用 --private-key
显式地将路径传递给您的密钥,或者再次将其设置为库存中的行为参数或 group/host 变量。
通过清单:
[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
---
使用 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 的所有权更改为我的用户,但运气不好。
您可以通过behavioral parameters在库存文件中定义用户。但是 -u
,就像你做的那样,应该有相同的结果。
可能是 Ansible 没有使用您的私钥,因为您没有 .ssh/config。 (大胆猜测!)您可以使用 --private-key
显式地将路径传递给您的密钥,或者再次将其设置为库存中的行为参数或 group/host 变量。
通过清单:
[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
---