How do you simulate "sudo su " in Ansible? I have a server where my user is able to sudo to the root user without a password, and then the root user can sudo to a third user without a password.  However, my user cannot sudo directly to the third user without a password.

Ansible's become directive uses sudo in the traditional manner, i.e. the one that requires prompting for my password.

I've tried putting become_user: root on a block and become_user: &lt;other-user&gt; on a task inside that block, but it appears Ansible overrides the block's definition, rather than nesting the sudo calls as I hoped.

Note: this question has also been asked on StackOverflow, but since there's no solution I figured I would repost it here, which I think is the better site for it.
I met the same situation. I have login1 for my machine, passwordless sudo and login2, under which I should perform some actions. I did not solve it by ansible means. But I made such a workaround:

- name: "Install nvm"
  shell: sudo -u buildkite-agent bash -c "&lt;my commands to be performed on behalf of buildkite-agent&gt;"
  become: true


Such a case:

- name: "Install nvm"
  shell: sudo -u buildkite-agent &lt;my commands to be performed on behalf of buildkite-agent&gt;
  become: true


do not change home to buildkite-agent's home, i.e. uses /root as home.