Ansible 以其他用户身份运行playbook

Ansible 以其他用户身份运行playbook,ansible,Ansible,我已将ansible user的ssh密钥添加到其他主机,因此所有主机上都允许ansible user。现在我想以root用户或任何其他服务用户(如apache等)的身份运行playbook。我已在playbook中指示用户为ansible。我在以root用户身份登录时运行playbook时遇到了以下提到的错误但当我以ansible用户身份登录时运行playbook时,一切正常 - hosts: nameservers user: ansible tasks: - name: che

我已将ansible user的ssh密钥添加到其他主机,因此所有主机上都允许ansible user。现在我想以root用户或任何其他服务用户(如apache等)的身份运行playbook。我已在playbook中指示用户为ansible。我在以root用户身份登录时运行playbook时遇到了以下提到的错误但当我以ansible用户身份登录时运行playbook时,一切正常

- 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}.
注意:我已在playbook中将IPs替换为x

setuser

user: ansible
在ansible配置文件中设置密钥路径

private_key_file = /home/ansible/.ssh/id_rsa

还是同一个问题,我在/ansible/hosts文件([nameservers]x.x.x.x ansible_user=ansible)中添加了一行,尝试使用ssh命令验证您是否可以连接
ssh-i/path/to/sshkeyansible@x.x.x.x
没有输入其他主机的密码,我无法连接<代码>ssh-i/home/ansible/.ssh/id\u rsa.pubansible@x.x.x.x否您必须使用私钥,私钥的命名应基于您的公钥
id\u rsa
以及您可以连接的
.pub
扩展名
[root@dev剧本]#ssh-i/home/ansible/.ssh/id\u rsaansible@x.x.x.x最后一次登录:周六8月1日03:26:43 2020从x.x.x.x[ansible@host1~]$