# ansible asks for sudo password but local command does not

**URL:** <https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559>\
**Category:** Ansible Project\
**Created:** [September 15, 2016, 4:51pm UTC](https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559 "2016-09-15T16:51:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Michel](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Mike\_Michel](https://forum.ansible.com/u/Mike_Michel)\
**Post date:** [September 15, 2016, 4:51pm UTC](https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559/1 "2016-09-15T16:51:24Z")

</div>

Hi,

i am having trouble to execute a command which needs sudo on the remote host. when i execute it directly on the host with sudo there is no ask for password but when using ansible it fails with "sudo: a password is required

i don’t have root rights on the remote and i am using a jumphost. i tried all the “become” vodoo but no luck yet.

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [September 16, 2016, 8:03am UTC](https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559/2 "2016-09-16T08:03:35Z")

</div>

> When i am directly on the target host as user john “sudo yum install htop” works without asking for a password so i guess NOPASSWD is set for john. I don’t even have a password. I connect via ssh key.

Ansible doesn’t do this:

`  
ssh john@a-host sudo yum install htop

`

Ansible uploads a python script which is run using sudo. Something like:

`  
scp tmp-script john@a-host:~/.ansible/tmp/…  
ssh john@a-host sudo python ~/.ansble/tmp/…

`

So sudo NOPASSWD for yum doesn’t help.

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [September 17, 2016, 6:58am UTC](https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559/3 "2016-09-17T06:58:18Z")

</div>

Is there a reason you’re not using the yum module?

---

<div class="post-metadata">

**Author:** ![Mike\_Michel](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Mike\_Michel](https://forum.ansible.com/u/Mike_Michel)\
**Post date:** [September 19, 2016, 7:21pm UTC](https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559/4 "2016-09-19T19:21:20Z")

</div>

@paul  
thx, though i knew it works like that i did not came to the idea to ask for python permission, what i did now.

@alexaner  
same problem as it is still python which gets executed:

sudo -H -S -n -u root /bin/sh -c ‘"’“'”‘"’“'”‘"’“‘echo BECOME-SUCCESS-mukfdpvotlpobkadiwdhuktbihrwsnnr; LANG=en\_US.utf8 LC\_ALL=en\_US.utf8 LC\_MESSAGES=en\_US.utf8 /usr/bin/python /home/john/.ansible/tmp/ansible-tmp-1474312334.89-150221606981760/setup; rm -rf “/home/john/.ansible/tmp/ansible-tmp-1474312334.89-150221606981760/” \> /dev/null 2\>&1’”‘"’“'”‘"’“'”‘"’ && sleep 0’“'”‘’

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [September 20, 2016, 6:10am UTC](https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559/5 "2016-09-20T06:10:17Z")

</div>

> sudo -H -S -n -u root /bin/sh -c ‘"’“'”‘"’“'”‘"’“‘echo BECOME-SUCCESS-mukfdpvotlpobkadiwdhuktbihrwsnnr; LANG=en\_US.utf8 LC\_ALL=en\_US.utf8 LC\_MESSAGES=en\_US.utf8 /usr/bin/python /home/john/.ansible/tmp/ansible-tmp-1474312334.89-150221606981760/setup; rm -rf “/home/john/.ansible/tmp/ansible-tmp-1474312334.89-150221606981760/” \> /dev/null 2\>&1’”‘"’“'”‘"’“'”‘"’ && sleep 0’“'”‘’

Ok, I said “something like”, because I didn’t have a machine to dig up the details on. But clearly you were able to do that. Look at the command. It’s sudo … /bin/sh .

So NOPASSWD: for /bin/sh. But really you should just give wildcard NOPASSWD for running ansible. There’s very little difference in NOPASSWD for /bin/sh and everything. Or input the password using --ask-become-pass

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Mike\_Michel](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@Mike\_Michel](https://forum.ansible.com/u/Mike_Michel)\
**Post date:** [September 22, 2016, 7:24am UTC](https://forum.ansible.com/t/ansible-asks-for-sudo-password-but-local-command-does-not/22559/6 "2016-09-22T07:24:15Z")

</div>

jep, NOPASSWD: for /bin/sh did it. I don’t have (or should i say “had”) root on the target server.

thanks

Mike
