# Issue | sudo su -  | ansible

**URL:** <https://forum.ansible.com/t/issue-sudo-su-ansible/35290>\
**Category:** Ansible Project\
**Created:** [June 5, 2021, 12:57pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290 "2021-06-05T12:57:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jatinder\_Jawanda](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jatinder\_Jawanda](https://forum.ansible.com/u/Jatinder_Jawanda)\
**Post date:** [June 5, 2021, 12:57pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/1 "2021-06-05T12:57:52Z")

</div>

Is it possible to run “ **sudo su -** ” in ansible with non-root user

```auto
- name: test
hosts: example.com
gather_facts: false
any_errors_fatal: true
become: true
become_exe: "sudo su - "
become_method: su
remote_user: test_user
tasks:
- name: check the user after sudo
shell: whoami

register: whoami

- debug:
msg: "{{ whoami }}"

Regards,
Jatinder Jawanda
```

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [June 5, 2021, 1:01pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/2 "2021-06-05T13:01:03Z")

</div>

Hi,

this is supported with the community.general.sudosu become plugin:  
[https://docs.ansible.com/ansible/latest/collections/community/general/sudosu\_become.html](https://docs.ansible.com/ansible/latest/collections/community/general/sudosu_become.html)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Jatinder\_Jawanda](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jatinder\_Jawanda](https://forum.ansible.com/u/Jatinder_Jawanda)\
**Post date:** [June 5, 2021, 1:08pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/3 "2021-06-05T13:08:21Z")

</div>

Hey Felix,

I was looking at this documentation and not sure how to use it.  
Is it possible if you can share a working code. I tried this below with this plugin but I was not able to make it run.  
**ansible [example.com](http://example.com) -i inventory/example -m shell -a “whoami” -e “ansible\_ssh\_pass=test@123” -e “ansible\_sudo\_pass=test@123” -u test\_user -b -e “ansible\_become\_method=sudosu” -e -e “ansible\_become\_exe=sudo su -”**

In sudoers I have following  
**test\_user ALL=(root) /bin/su -**

Regards,  
Jatinder Jawanda

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [June 5, 2021, 1:13pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/4 "2021-06-05T13:13:04Z")

</div>

Hi Jatinder,

have you tried `ansible_become_method=community.general.sudosu` instead  
of `ansible_become_method=sudosu`? The later will definitely not work,  
since `sudosu` is not that old that it still has a short name.

(Besides that, I haven't used it, so I unfortunately cannot share  
working code.)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Jatinder\_Jawanda](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jatinder\_Jawanda](https://forum.ansible.com/u/Jatinder_Jawanda)\
**Post date:** [June 5, 2021, 1:26pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/5 "2021-06-05T13:26:19Z")

</div>

Nope, its not working !!

**ansible [example.com](http://example.com) -i inventory/example -m shell -a “whoami” -e “ansible\_ssh\_pass=test@123” -e “ansible\_sudo\_pass=test@123” -u test\_user -b -e "ansible\_become\_method=community.general.sudosu**  
FAILED! =\> {  
“changed”: false,  
“module\_stderr”: “Shared connection to [example.com](http://example.com) closed.\r\n”,  
“module\_stdout”: “\r\n”,  
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,  
“rc”: 1  
}

Regards,  
Jatinder Jawanda

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [June 5, 2021, 4:05pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/6 "2021-06-05T16:05:14Z")

</div>

Hi Jatinder,

it would be interesting to see more debug output. Have you tried  
running ansible additionally with `-vvv`?

Best,  
Felix

---

<div class="post-metadata">

**Author:** ![Jatinder\_Jawanda](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jatinder\_Jawanda](https://forum.ansible.com/u/Jatinder_Jawanda)\
**Post date:** [June 5, 2021, 4:33pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/7 "2021-06-05T16:33:08Z")

</div>

Here are the debug logs.  
**ansible localhost -m ping -u test\_user --become -e “ansible\_ssh\_pass=test@123” -e “ansible\_sudo\_pass=test@123” -e “ansible\_become\_method=community.general.sudosu” -vvvv**

META: ran handlers  
\<127.0.0.1\> ESTABLISH LOCAL CONNECTION FOR USER: test\_user  
\<127.0.0.1\> EXEC /bin/sh -c ‘echo ~test\_user && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /home/test_user/.ansible/tmp`”&& mkdir /home/test\_user/.ansible/tmp/ansible-tmp-1622910467.15-29606-264197614406164 && echo ansible-tmp-1622910467.15-29606-264197614406164=“`echo /home/test_user/.ansible/tmp/ansible-tmp-1622910467.15-29606-264197614406164`” ) && sleep 0’  
Using module file /opt/dma/.venv\_ansible/lib/python2.7/site-packages/ansible/modules/system/ping.py  
\<127.0.0.1\> PUT /home/test\_user/.ansible/tmp/ansible-local-29579YwKbAR/tmpfCP59y TO /home/test\_user/.ansible/tmp/ansible-tmp-1622910467.15-29606-264197614406164/AnsiballZ\_ping.py  
\<127.0.0.1\> EXEC /bin/sh -c ‘chmod u+x /home/test\_user/.ansible/tmp/ansible-tmp-1622910467.15-29606-264197614406164/ /home/test\_user/.ansible/tmp/ansible-tmp-1622910467.15-29606-264197614406164/AnsiballZ\_ping.py && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘sudo -H -S -p “[sudo via ansible, key=gouhehrxcdmgfhcjdbeadtdpeciznpks] password:” su -l root /bin/sh -c ‘"’“‘echo BECOME-SUCCESS-gouhehrxcdmgfhcjdbeadtdpeciznpks ; /opt/dma/.venv\_ansible/bin/python /home/test\_user/.ansible/tmp/ansible-tmp-1622910467.15-29606-264197614406164/AnsiballZ\_ping.py’”’"’ && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘rm -f -r /home/test\_user/.ansible/tmp/ansible-tmp-1622910467.15-29606-264197614406164/ \> /dev/null 2\>&1 && sleep 0’  
localhost | FAILED! =\> {  
“changed”: false,  
“module\_stderr”: “”,  
“module\_stdout”: “”,  
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,  
“rc”: 1  
}

Regards,  
Jatinder Jawanda

---

<div class="post-metadata">

**Author:** ![Jatinder\_Jawanda](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jatinder\_Jawanda](https://forum.ansible.com/u/Jatinder_Jawanda)\
**Post date:** [June 5, 2021, 4:40pm UTC](https://forum.ansible.com/t/issue-sudo-su-ansible/35290/8 "2021-06-05T16:40:59Z")

</div>

Furthermore, If I make a change in sudeors like below then --become-method=sudo also starts working.

Before:  
test\_user ALL=(root) /bin/su -

After:  
test\_user ALL=(root) /bin/su

Regards,  
Jatinder Jawanda
