# sudo not working when using ansible\_ssh\_user and ansible\_become\_user

**URL:** <https://forum.ansible.com/t/sudo-not-working-when-using-ansible-ssh-user-and-ansible-become-user/19349>\
**Category:** Ansible Project\
**Created:** [September 24, 2015, 3:58pm UTC](https://forum.ansible.com/t/sudo-not-working-when-using-ansible-ssh-user-and-ansible-become-user/19349 "2015-09-24T15:58:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [September 24, 2015, 3:58pm UTC](https://forum.ansible.com/t/sudo-not-working-when-using-ansible-ssh-user-and-ansible-become-user/19349/1 "2015-09-24T15:58:36Z")

</div>

hey, i’m having issues with privilege escalation on OSX (all machines at version 10.10 with ansible ):

we are using ansible to help manage our workstations, and when i execute playbooks locally using ansible\_connection=local on the target as the user (josh in this case), tasks with sudo: true work fine

when executing from my machine any sudo tasks fail with permissions errors.

i’m using an inventory line like

josh ansible\_ssh\_host=Joshs-MacBook-Pro.local ansible\_ssh\_user=sysadmin ansible\_become\_user=josh

Josh’s machine has a sysadmin user that i can log into using my ssh key that is part of the admin group and has

sysadmin ALL=(ALL) NOPASSWD:ALL

in the /etc/sudoers file. the josh user is also in admin and has “no password” setup in sudoers.

when executing from my machine, i get errors like

failed: [josh] =\> {“failed”: true, “parsed”: false}  
BECOME-SUCCESS-bcpvkbjdbokqphwizmnpqwllqehnwiyh  
Traceback (most recent call last):  
File “/tmp/ansible-tmp-1443108894.49-142723340060191/lineinfile”, line 2217, in   
main()  
File “/tmp/ansible-tmp-1443108894.49-142723340060191/lineinfile”, line 394, in main  
ins\_aft, ins\_bef, create, backup, backrefs)  
File “/tmp/ansible-tmp-1443108894.49-142723340060191/lineinfile”, line 201, in present  
f = open(dest, ‘rb’)  
IOError: [Errno 13] Permission denied: ‘/etc/sudoers’  
OpenSSH\_6.2p2, OSSLShim 0.9.8r 8 Dec 2011  
debug1: Reading configuration data /Users/nrser/.ssh/config  
debug1: Reading configuration data /etc/ssh\_config  
debug1: /etc/ssh\_config line 20: Applying options for \*  
debug1: /etc/ssh\_config line 53: Applying options for \*  
debug1: auto-mux: Trying existing master  
debug1: mux\_client\_request\_session: master session id: 2  
Shared connection to Joshs-MacBook-Pro.local closed.

FATAL: all hosts have already failed – aborting

i also get errors when trying anything with sudo or become\_user, not just touching /etc/sudoers.

all the users involved have no-password sudo permissions… i don’t understand why they can’t escalate.

anyone have any info / ideas / suggestions?

thanks, Neil.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [September 24, 2015, 5:28pm UTC](https://forum.ansible.com/t/sudo-not-working-when-using-ansible-ssh-user-and-ansible-become-user/19349/2 "2015-09-24T17:28:46Z")

</div>

Hi Neil,

From the debug output, it’s trying to connect as nruser:  
debug1: Reading configuration data /Users/nrser/.ssh/config

Do you know where have you specified that ansible should connect as nruser?

Joanna

---

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [September 24, 2015, 5:35pm UTC](https://forum.ansible.com/t/sudo-not-working-when-using-ansible-ssh-user-and-ansible-become-user/19349/3 "2015-09-24T17:35:06Z")

</div>

nrser is the user on my machine. i understood ansible\_ssh\_user=sysadmin to mean it would connect as sysadmin.

this works fine from my machine to the target:

ssh sysadmin@Joshs-MacBook-Pro.local

i’m able to execute non-sudo tasks just fine, and nrser doesn’t exist as a user on the target machine, so it can’t be connecting as nrser… i’m pretty sure it’s connecting as sysadmin

---

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [September 24, 2015, 5:40pm UTC](https://forum.ansible.com/t/sudo-not-working-when-using-ansible-ssh-user-and-ansible-become-user/19349/4 "2015-09-24T17:40:13Z")

</div>

i believe the reason we’re seeing /Users/nrser/.ssh is because that’s the user i’m logged in as on the master and where theid\_rsa key that it’s using to connect is.
