我已将ansible用户的ssh密钥添加到其他主机,因此所有主机上都允许ansible用户。现在,我想以root用户或其他服务用户(如apache等)运行playbook。我已经在我的playbook中将用户指示为ansible当我以根用户身份登录时运行剧本时,出现以下错误。 但是当我以正常用户身份登录并运行剧本时,一切正常。
- hosts: nameservers
user: ansible
tasks:
- name: check hostname
command: hostname
错误
[root@dev playbooks]# ansible-playbook pingtest.yml
PLAY [nameservers] *********************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
fatal: [x.x.x.x]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
fatal: [x.x.x.x]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}
fatal: [x.x.x.x]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", "unreachable": true}.
注意:我已经用x替换了IP
答案 0 :(得分:1)
剧本中的setuser
user: ansible
在可配置文件中设置密钥路径
private_key_file = /home/ansible/.ssh/id_rsa