How do you simulate "sudo su " in Ansible?
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.