i got this working without a problem when the remote serveur doesn't have the ssh parameter :

PermitRootLogin yes

My working ansible command:

[ansible@myansible ~]$ ansible remoteserveur -a "cat /etc/sudoers"

I want to change the ssh parameter on all my servers to PermitRootLogin no for the security. When this is done, it's no more working.

    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).",
    "unreachable": true

How could i keep my ansible's user being a normal user and having the possibility via ansible to run command as root.

Many thanks for your attention.


Are you sure you do not have "become: yes" directive in your Ansible playbook? This directive is responsible for privileged access for the Ansible agent.



Many thanks Nikolay, it gave me the good way to resolve the problem. I finaly use :

ansible-playbook permitrootlogin.yml -b -K

-b for "become" and -K "ask for privilege escalation password"

TASK [Disallow root SSH access] ******************************************************************************************************************************************************
ok: [server1]
ok: [server2]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.