# include with remote\_user

**URL:** <https://forum.ansible.com/t/include-with-remote-user/15110>\
**Category:** Ansible Project\
**Created:** [April 29, 2014, 7:31am UTC](https://forum.ansible.com/t/include-with-remote-user/15110 "2014-04-29T07:31:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_J](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@A\_J](https://forum.ansible.com/u/A_J)\
**Post date:** [April 29, 2014, 7:31am UTC](https://forum.ansible.com/t/include-with-remote-user/15110/1 "2014-04-29T07:31:50Z")

</div>

Hi, I’m new to ansible and have been unable to achieve the following:  
I would like to include tasks in my playbook and run them with another user that’s running the playbook.

I have tried the following, without success:

`

- include: mytasks.yml remote\_user=toto

`

I have also tried this (from the documentation)

`

- include: mytasks.yml  
vars:  
remote\_user: toto

`

but again, when running the playbook, the tasks are executed with the playbook remote user and not the one defined next to the include.

I’m using ansible 1.5.4.

Is there anyway to do this ? or do I have to specify the remote\_user for each and every task in the tasks file ?  
thanks a lot,  
regards,  
ozb.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 29, 2014, 12:31pm UTC](https://forum.ansible.com/t/include-with-remote-user/15110/2 "2014-04-29T12:31:12Z")

</div>

While a keyword in ansible for a task or play, remote\_user is not a magic variable here any more than “antelope\_jetpack” is likely to work. It’s just the wrong variable name is all 🙂

You can set “ansible\_ssh\_user” in inventory as a variable to control the remote user, which could also be set here.

Generally people set this at play level instead.

- hosts: postgresql\_steps  
remote\_user: postgres

Etc

Though usually most people would do this kind of thing with “sudo\_user” instead, and just pass the connecting user on the command line or assume the default.

---

<div class="post-metadata">

**Author:** ![A\_J](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@A\_J](https://forum.ansible.com/u/A_J)\
**Post date:** [April 29, 2014, 2:03pm UTC](https://forum.ansible.com/t/include-with-remote-user/15110/3 "2014-04-29T14:03:19Z")

</div>

thanks for the quick answer.  
I think I did not express myself properly:

I was actually wondering how to change the remote (user) when executing an included tasks file.

My playbook already defines the remote\_user (root), but I just want to run one of my included tasks as another user:

`

- hosts: ansible-localhost  
remote\_user: root

tasks:

- include: tasks/some\_tasks.yml

- include: tasks/some\_other\_tasks\_to\_be\_run\_with\_user\_toto.yml  
remote\_user: toto

`

The goal would be to avoid to repeat the “remote\_user” for all the tasks in my included file:

`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 29, 2014, 3:44pm UTC](https://forum.ansible.com/t/include-with-remote-user/15110/4 "2014-04-29T15:44:09Z")

</div>

If you pass the variable as ansible\_ssh\_user instead of “remote\_user” it should do what you request, however, this is more idiomatic:

- hosts: ansible-localhost  
remote\_user: root  
tasks:

- include: tasks/some\_tasks.yml

- hosts: ansible-localhost  
remote\_user: toto

- include: tasks/some\_other\_tasks\_to\_be\_run\_with\_user\_toto.yml

---

<div class="post-metadata">

**Author:** ![A\_J](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@A\_J](https://forum.ansible.com/u/A_J)\
**Post date:** [April 30, 2014, 7:21am UTC](https://forum.ansible.com/t/include-with-remote-user/15110/5 "2014-04-30T07:21:52Z")

</div>

ok I will try that,  
thanks a lot !
