ad-hoc $ ansible -u root Permission denied

  • Default ansible 2.9 configuration.

  • User user exists both on the control and the hosts.

  • Control and hosts have each other's ssh public keys for both users.

From the control host:

root$ ansible all -a "echo whatever" works

user$ ansible all -a "echo whatever" works

user$ ansible all -a "echo whatever" -u root doesn't work.

Error: ... Failed to connect to the host via ssh: root@xhost: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password) ...

I tried using --become* with no success. How to make that work? what am I missing?


Make sure you have root credentials of all remote hosts. You can copy them to your host using ssh-copy-id for example.