# sudo does not seem to work with ansible 1.9

**URL:** <https://forum.ansible.com/t/sudo-does-not-seem-to-work-with-ansible-1-9/19125>\
**Category:** Ansible Project\
**Created:** [August 27, 2015, 2:39pm UTC](https://forum.ansible.com/t/sudo-does-not-seem-to-work-with-ansible-1-9/19125 "2015-08-27T14:39:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan\_Hradek](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Stephan\_Hradek](https://forum.ansible.com/u/Stephan_Hradek)\
**Post date:** [August 27, 2015, 2:39pm UTC](https://forum.ansible.com/t/sudo-does-not-seem-to-work-with-ansible-1-9/19125/1 "2015-08-27T14:39:14Z")

</div>

It seems, the sudo option does not work.

I’m asked for the password, but I do not see it working.

Am I missing something?

`  
$ ansible -vvvv all --sudo-user sudouser --ask-sudo-pass -a ‘ls -al /opt/SP/sudouser/scripts’  
SUDO password:  
 ESTABLISH CONNECTION FOR USER: cygwinme  
 REMOTE\_MODULE command ls -al /opt/SP/sudouser/scripts  
 EXEC ssh -C -tt -vvv -o ControlMaster=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 myhost /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1440686159.76-102172331141486 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1440686159.76-102172331141486 && echo $HOME/.ansible/tmp/ansible-tmp-1440686159.76-102172331141486’  
 PUT /tmp/tmp3pJW5R TO /home/linuxme/.ansible/tmp/ansible-tmp-1440686159.76-102172331141486/command  
 EXEC ssh -C -tt -vvv -o ControlMaster=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 myhost /bin/sh -c ‘LANG=en\_US.UTF-8 LC\_CTYPE=en\_US.UTF-8 /usr/bin/python /home/linuxme/.ansible/tmp/ansible-tmp-1440686159.76-102172331141486/command; rm -rf /home/linuxme/.ansible/tmp/ansible-tmp-1440686159.76-102172331141486/ \>/dev/null 2\>&1’  
myhost | FAILED | rc=2 \>\>  
ls: cannot access /opt/SP/sudouser/scripts: Permission denied

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 27, 2015, 2:53pm UTC](https://forum.ansible.com/t/sudo-does-not-seem-to-work-with-ansible-1-9/19125/2 "2015-08-27T14:53:35Z")

</div>

you are missing the option to enable sudo (--sudo), setting user and  
password do not force sudo as you can have that selectively set at the  
host level.

---

<div class="post-metadata">

**Author:** ![Stephan\_Hradek](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Stephan\_Hradek](https://forum.ansible.com/u/Stephan_Hradek)\
**Post date:** [August 27, 2015, 3:55pm UTC](https://forum.ansible.com/t/sudo-does-not-seem-to-work-with-ansible-1-9/19125/3 "2015-08-27T15:55:35Z")

</div>

Thanks a lot. That did it and also showed me that it seems impossible for me to use ansible ☹

Unfortunately I’m onlyi allowed to do “sudo -u sudouser” ans not “sudo -u sudouser some arbitrary command”.

This is fine in an interactive session as the allowed command will leave me in a bash. But ansible tries to execute something like:

`/bin/sh -c echo BECOME-SUCCESS-somegibberish; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1440690655.74-51912605722035/command`

Or is there also a way around this?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 27, 2015, 4:03pm UTC](https://forum.ansible.com/t/sudo-does-not-seem-to-work-with-ansible-1-9/19125/4 "2015-08-27T16:03:12Z")

</div>

Allowing you to get a shell as a user has no real security above  
allowing you to run any command directly as a user, this is a minor  
sudoers configuration change.

Ansible works by copying scripts to temp dirs and running them (the  
modules), this it how it avoids having an agent. If you cannot make  
the change above and still don't have permissions to do this you might  
want to look at ansible-pull.

---

<div class="post-metadata">

**Author:** ![Stephan\_Hradek](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Stephan\_Hradek](https://forum.ansible.com/u/Stephan_Hradek)\
**Post date:** [August 27, 2015, 4:27pm UTC](https://forum.ansible.com/t/sudo-does-not-seem-to-work-with-ansible-1-9/19125/5 "2015-08-27T16:27:24Z")

</div>

> Allowing you to get a shell as a user has no real security above  
> allowing you to run any command directly as a user, this is a minor  
> sudoers configuration change.

I totally agree with you. Unfortunately I’m not in the position to make this change or convince someone to do that.

> ansible-pull.

Will check what that is.

Thanks again
