# roles with different users

**URL:** <https://forum.ansible.com/t/roles-with-different-users/13214>\
**Category:** Ansible Project\
**Created:** [July 29, 2013, 2:34pm UTC](https://forum.ansible.com/t/roles-with-different-users/13214 "2013-07-29T14:34:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lars\_svenson](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@lars\_svenson](https://forum.ansible.com/u/lars_svenson)\
**Post date:** [July 29, 2013, 2:34pm UTC](https://forum.ansible.com/t/roles-with-different-users/13214/1 "2013-07-29T14:34:49Z")

</div>

Hello community,

I tried to change my setup to use roles now 🙂

But I have a problem and can’t help myself.

My main.yml Playbook is like this:

- hosts: foobar  
roles:
- common
- add\_basic\_software

Now the playbook is executed by my current logged in. That’s logical and not the point.

What I want to do is to execute the common role by user “foo” and the “add\_basic\_software” role by user “bar”. Is there any possibility to do that? I expect that in the roles/common/tasks/main.yml should be no user mentioned.

Do you have any suggestions how to realize this ?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 29, 2013, 2:48pm UTC](https://forum.ansible.com/t/roles-with-different-users/13214/2 "2013-07-29T14:48:17Z")

</div>

You’ll want two plays here. In the first one, add “user: foo” right under hosts. In the second, add “user: bar”.

- hosts: blarg  
user: foo  
roles:

- common

- hosts: blarg  
user: bar  
roles:

- add\_basic\_software

You can of course also just use one user and set sudo\_user on a per task basis, if you wanted.

---

<div class="post-metadata">

**Author:** ![lars\_svenson](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@lars\_svenson](https://forum.ansible.com/u/lars_svenson)\
**Post date:** [July 29, 2013, 3:01pm UTC](https://forum.ansible.com/t/roles-with-different-users/13214/3 "2013-07-29T15:01:12Z")

</div>

Awesome thanks - should imagine that by myself ^^

but blarg was just a placeholder and is in my playbook “{{ blarg }}”. I assign it via vars\_prompt.

Is there a possibility to just do that one time in the first playbook? 🙂

Thanks for your work and ansible.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 29, 2013, 6:46pm UTC](https://forum.ansible.com/t/roles-with-different-users/13214/4 "2013-07-29T18:46:07Z")

</div>

"but blarg was just a placeholder and is in my playbook “{{ blarg }}”. I assign it via vars\_prompt. "

IIRC, hosts gets evaluated before vars\_prompt.

you can definitely use -e on the command line.
