# Issues with sudo\_user

**URL:** <https://forum.ansible.com/t/issues-with-sudo-user/17772>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [March 18, 2015, 2:08pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772 "2015-03-18T14:08:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacek](https://forum.ansible.com/u/Jacek)\
**Post date:** [March 18, 2015, 2:08pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/1 "2015-03-18T14:08:30Z")

</div>

Hi,

I’m using “ansible 1.9 (devel b11be68249) last updated 2015/03/17 12:39:00 (GMT +000)” and am facing an issue with the ‘sudo\_user’ switch.  
My role fails on the postgres user not being able to be authenticated.  
The ansible command host is Ubuntu, ansible target is localhost

My playbook looks like 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:** [March 18, 2015, 2:10pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/2 "2015-03-18T14:10:28Z")

</div>

So issue seems to be when sudo\_user is set at role level, not at play level.

---

<div class="post-metadata">

**Author:** ![Jacek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacek](https://forum.ansible.com/u/Jacek)\
**Post date:** [March 18, 2015, 2:16pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/3 "2015-03-18T14:16:48Z")

</div>

Hi Brian,

Not really. If sudo\_user is set only at the play level the sudo user is root:

------- excerpt from the stdout when running with -vvvv --------  
"[sudo via ansible, key=vksodlsoxtyvcfgxeosslbsttkfqyzcb] password: " -u root /bin/sh -c

---

<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:** [March 18, 2015, 2:41pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/4 "2015-03-18T14:41:28Z")

</div>

can you show test with the issue at the play level? i cannot  
reproduce, i used the following:

- hosts: testmachine  
&nbsp;&nbsp;sudo: yes  
&nbsp;&nbsp;sudo\_user: nobody  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- template:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: testfile  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/z  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mode: 0600  
with -vvvv i can see:  
/bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible,  
key=cxwmwhlrjpfrghjcbaabmtadbvgcgouq] password: " -u nobody /bin/sh -c  
'"'"'echo BECOME-SUCCESS-cxwmwhlrjpfrghjcbaabmtadbvgcgouq; LANG=C  
LC\_CTYPE=C /usr/bin/python  
/tmp/ansible-tmp-1426689710.81-275921666186925/copy'"'"''

---

<div class="post-metadata">

**Author:** ![Jacek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacek](https://forum.ansible.com/u/Jacek)\
**Post date:** [March 18, 2015, 2:56pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/5 "2015-03-18T14:56:15Z")

</div>

What do you mean by ‘show test’?  
Did you try when the target machine (your ‘testmachine’) is set to localhost in the inventory?

W dniu środa, 18 marca 2015 14:41:34 UTC użytkownik Brian Coca napisał:

---

<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:** [March 18, 2015, 2:59pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/6 "2015-03-18T14:59:42Z")

</div>

same result if host is localhost, i can reproduce the issue with roles  
not picking up sudo\_user but not with a play.

---

<div class="post-metadata">

**Author:** ![Jacek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacek](https://forum.ansible.com/u/Jacek)\
**Post date:** [March 18, 2015, 3:02pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/7 "2015-03-18T15:02:14Z")

</div>

Sorry, I need to leave now but will get back to you with an example later today.

Cheers,  
Jacek

W dniu środa, 18 marca 2015 14:59:46 UTC użytkownik Brian Coca napisał:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 18, 2015, 3:12pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/8 "2015-03-18T15:12:50Z")

</div>

Could it be related to [https://github.com/ansible/ansible/issues/10475](https://github.com/ansible/ansible/issues/10475) ?

---

<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:** [March 18, 2015, 3:16pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/9 "2015-03-18T15:16:49Z")

</div>

No, that is probably a path in the old code that bypasses sudo if you  
are already root.

---

<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:** [March 18, 2015, 3:46pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/10 "2015-03-18T15:46:10Z")

</div>

tested with 1.8.4, putting sudo\_user on role does not seem to work either.

---

<div class="post-metadata">

**Author:** ![Jacek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacek](https://forum.ansible.com/u/Jacek)\
**Post date:** [March 19, 2015, 1:43pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/11 "2015-03-19T13:43:08Z")

</div>

Hi All,

I’m sending the play and role for you to check (see below).

It doesn’t work right (shows ‘postgres’, ‘root’) with:

ansible 1.9 (devel 73f5a1fcdd) last updated 2015/03/19 13:38:54 (GMT +000)  
lib/ansible/modules/core: (detached HEAD 76198a8223) last updated 2015/03/19 13:39:04 (GMT +000)  
lib/ansible/modules/extras: (detached HEAD cb848fcd9e) last updated 2015/03/19 13:39:04 (GMT +000)  
v2/ansible/modules/core: (detached HEAD 34784b7a61) last updated 2015/03/17 12:39:06 (GMT +000)  
v2/ansible/modules/extras: (detached HEAD 46e316a20a) last updated 2015/03/19 13:39:04 (GMT +000)  
configured module search path = None

It does work correctly (shows ‘postgres’, ‘postgres’) with:

ansible 1.9 (devel ffb281d96c) last updated 2015/03/19 13:32:20 (GMT +000)  
lib/ansible/modules/core: (detached HEAD 618806aeeb) last updated 2015/03/19 13:36:08 (GMT +000)  
lib/ansible/modules/extras: (detached HEAD 945da71ce4) last updated 2015/03/19 13:36:08 (GMT +000)  
v2/ansible/modules/core: (detached HEAD 34784b7a61) last updated 2015/03/17 12:39:06 (GMT +000)  
v2/ansible/modules/extras: (detached HEAD 650d740a3a) last updated 2015/03/19 13:36:09 (GMT +000)  
configured module search path = None

--------- test.yml ------

---

<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:** [March 19, 2015, 1:45pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/12 "2015-03-19T13:45:19Z")

</div>

Works as expected, setting sudo\_user at role level is not supported.  
You can set it at play or task level.

---

<div class="post-metadata">

**Author:** ![Jacek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacek](https://forum.ansible.com/u/Jacek)\
**Post date:** [March 19, 2015, 3:09pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/13 "2015-03-19T15:09:06Z")

</div>

Do you mean that within my original example I’ll need:

---

<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:** [March 19, 2015, 3:17pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/14 "2015-03-19T15:17:31Z")

</div>

I'm looking at the previous stable version 1.8.4 and it does not work  
there, in which version did this work for you?

---

<div class="post-metadata">

**Author:** ![Jacek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacek](https://forum.ansible.com/u/Jacek)\
**Post date:** [March 19, 2015, 8:01pm UTC](https://forum.ansible.com/t/issues-with-sudo-user/17772/15 "2015-03-19T20:01:21Z")

</div>

I always worked with sources straight from github. Previously, it worked with 1.7.? (can’t remember exactly) then, sometime in Feb or earlier, I updated to 1.9 (ffb281d96c) and it was ok, too.

W dniu czwartek, 19 marca 2015 15:17:40 UTC użytkownik Brian Coca napisał:
