# How to achieve sudo su  - root and run all command in ansible

**URL:** <https://forum.ansible.com/t/how-to-achieve-sudo-su-root-and-run-all-command-in-ansible/25183>\
**Category:** Ansible Project\
**Created:** [August 4, 2017, 11:27am UTC](https://forum.ansible.com/t/how-to-achieve-sudo-su-root-and-run-all-command-in-ansible/25183 "2017-08-04T11:27:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganesh\_Batwal](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Ganesh\_Batwal](https://forum.ansible.com/u/Ganesh_Batwal)\
**Post date:** [August 4, 2017, 11:27am UTC](https://forum.ansible.com/t/how-to-achieve-sudo-su-root-and-run-all-command-in-ansible/25183/1 "2017-08-04T11:27:27Z")

</div>

Hi All,  
We are not able to switch the ansible playbook connection to root id. eg. “sudo su -” and then execute the privilege commands. Kindly check and advice on correct approach.

Error messages :-"Sorry, user ganeshbatwal is not allowed to execute '/bin/sh -c echo BECOME-SUCCESS-ztghielsvyhxrzkvxzgqwsdmhgebdjrd;

Kindly note :- Due to security reasons we have blocked the " **/bin/sh -c**"execution in sudo configuration.

ansible-playbook passwd\_never\_expiry.yml --ask-become-pass  
SUDO password:

PLAY [172.28.43.87] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [172.28.43.87]: FAILED! =\> {“changed”: false, “failed”: true, “module\_stderr”: “Shared connection to 172.28.43.87 closed.\r\n”, “module\_stdout”: “Sorry, user ganeshbatwal is not allowed to execute ‘/bin/sh -c echo BECOME-SUCCESS-legcrwpoindiydrchivdirlopufgmioc; /usr/bin/python /home/ganeshbatwal/.ansible/tmp/ansible-tmp-1501845852.66-214235381292662/setup.py; rm -rf "/home/ganeshbatwal/.ansible/tmp/ansible-tmp-1501845852.66-214235381292662/" \> /dev/null 2\>&1’ as root on [jet-netline-websrvtestn2.jetairways.com](http://jet-netline-websrvtestn2.jetairways.com).\r\n”, “msg”: “MODULE FAILURE”}  
[WARNING]: Could not create retry file ‘/etc/ansible/passwd\_never\_expiry.retry’. [Errno 13] Permission denied:  
u’/etc/ansible/passwd\_never\_expiry.retry’

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
172.28.43.87 : ok=0 changed=0 unreachable=0 failed=1

Playboook details:-

cat passwd\_never\_expiry.yml

---

<div class="post-metadata">

**Author:** ![Ganesh\_Batwal](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Ganesh\_Batwal](https://forum.ansible.com/u/Ganesh_Batwal)\
**Post date:** [August 4, 2017, 11:36am UTC](https://forum.ansible.com/t/how-to-achieve-sudo-su-root-and-run-all-command-in-ansible/25183/2 "2017-08-04T11:36:02Z")

</div>

The below mention command is working fine with command prompt… How to configure the same via playbook.

ansible 172.28.43.87 -m shell -a ‘sudo chage -I -1 -m 0 -M 99999 -E -1 netline’ --become-user=root  
172.28.43.87 | SUCCESS | rc=0 \>\>

---

<div class="post-metadata">

**Author:** ![Utkarsh\_Sharma](https://avatars.discourse-cdn.com/v4/letter/u/ecc23a/32.png) [@Utkarsh\_Sharma](https://forum.ansible.com/u/Utkarsh_Sharma)\
**Post date:** [April 17, 2018, 2:40pm UTC](https://forum.ansible.com/t/how-to-achieve-sudo-su-root-and-run-all-command-in-ansible/25183/3 "2018-04-17T14:40:24Z")

</div>

Team, I am also facing the same issue. it works using the raw module but not in the playbook
