password not being accepted for sudo user with ansible

In 'sudo su - root' the root privilege is gained by sudo rather than su (that is why the latter doesn't ask for the root password, since it is invoked by a process already in the role of the root user).

However, in your setup you have specified become_method: su, which expects root's password.

So the fix will be to change become_method to sudo (or, if you know root's password, enter that one instead of your user's password).


sudo su - root is not the same thing as become_method: su.

su tries to switch to another user (by default, root) and requires you to authenticate as them (that is, enter their password). sudo is similar, except that it prompts for your password. To prevent this from being a security catastrophic issue, sudo only works for users who have been explicitly given access to it via /etc/sudoers.

When you use sudo su - root, you are saying:

  1. Elevate my privileges to root via sudo.
  2. With those elevated privileges, switch to the root user account.

Now, when you specify become_method: su in Ansible, you are telling Ansible to use su instead of sudo. The actual command will be different, but you can think of it as running the command su - root. See how that's different?

You should use become_method: sudo instead, or remove it entirely, as it's the default.