# ansible\_user\_id is set wrongly to 'root'

**URL:** <https://forum.ansible.com/t/ansible-user-id-is-set-wrongly-to-root/14214>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [December 24, 2013, 4:40pm UTC](https://forum.ansible.com/t/ansible-user-id-is-set-wrongly-to-root/14214 "2013-12-24T16:40:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pancho\_horrillo](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@pancho\_horrillo](https://forum.ansible.com/u/pancho_horrillo)\
**Post date:** [December 24, 2013, 4:40pm UTC](https://forum.ansible.com/t/ansible-user-id-is-set-wrongly-to-root/14214/1 "2013-12-24T16:40:22Z")

</div>

Hi!

I've split some tasks in two roles, one with plays requiring sudo and  
the other with plays not requiring it (hence run as 'ubuntu').

I have a top level playbook that maps the same group of hosts to both  
roles, the first enabling sudo, the second disabling it, like this:

site.yml:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [December 24, 2013, 4:44pm UTC](https://forum.ansible.com/t/ansible-user-id-is-set-wrongly-to-root/14214/2 "2013-12-24T16:44:43Z")

</div>

The issue looks you are dealing with cached facts, if you remove the sudo  
from the play level and set it at the somerole-sudo level (or have previous  
play/task w/o sudo gather\_facts) you'll get the user you expect.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [December 24, 2013, 4:46pm UTC](https://forum.ansible.com/t/ansible-user-id-is-set-wrongly-to-root/14214/3 "2013-12-24T16:46:11Z")

</div>

Also you can force new facts to be gathered in the 2nd play with gather\_facts: True. The implicit version uses the cache, the explicit will actually force a fact gathering.

---

<div class="post-metadata">

**Author:** ![pancho\_horrillo](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@pancho\_horrillo](https://forum.ansible.com/u/pancho_horrillo)\
**Post date:** [December 24, 2013, 4:59pm UTC](https://forum.ansible.com/t/ansible-user-id-is-set-wrongly-to-root/14214/4 "2013-12-24T16:59:43Z")

</div>

It makes sense. I've tried both methods you propose and in both cases  
it works like a charm.

Thanks a lot, Brian!

Happy hacking,
