# remote\_user var persists between plays?

**URL:** <https://forum.ansible.com/t/remote-user-var-persists-between-plays/19817>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [November 20, 2015, 5:25pm UTC](https://forum.ansible.com/t/remote-user-var-persists-between-plays/19817 "2015-11-20T17:25:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [November 20, 2015, 5:25pm UTC](https://forum.ansible.com/t/remote-user-var-persists-between-plays/19817/1 "2015-11-20T17:25:55Z")

</div>

Ansible v1.9.4

I have a playbook that I launch with:

`$ ansible-playbook build.yml`

build.yml includes set\_os.yml (just a set of tasks) that launches some ec2 instances. build.yml looks like this.

`- name: Build stuff`  
`hosts: localhost`  
`sudo: False`  
`gather_facts: False`  
`tasks:`  
`- include: set_os.yml`  
`- include: build_soft.yml`

In the file set\_os.yml, I set the remote user like this:

`

- set\_fact:  
ruser: ubuntu  
`

When I include build\_soft.yml above (a new play), I want to use that remote user to login and configure the new EC2 instance like so:

`

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [November 20, 2015, 9:13pm UTC](https://forum.ansible.com/t/remote-user-var-persists-between-plays/19817/2 "2015-11-20T21:13:28Z")

</div>

This: [http://stackoverflow.com/questions/31708736/passing-variables-between-nested-playbooks](http://stackoverflow.com/questions/31708736/passing-variables-between-nested-playbooks)  
suggests that if I change the “hosts” (which I do), then the set\_fact vars are NOT persisted between plays. Correct?

J

---

<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:** [November 20, 2015, 9:37pm UTC](https://forum.ansible.com/t/remote-user-var-persists-between-plays/19817/3 "2015-11-20T21:37:13Z")

</div>

set\_fact sets a variable for the hosts that are in the play. It does not set global variables.

As such, if you target different hosts between the different plays, then you do not have direct access to that fact, as it was set on another host.

---

<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:** [November 20, 2015, 9:40pm UTC](https://forum.ansible.com/t/remote-user-var-persists-between-plays/19817/4 "2015-11-20T21:40:29Z")

</div>

vars should still be there though,  
hostvars['original\_host']['varname'] should allow you to see the var  
from another host.

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [November 20, 2015, 10:33pm UTC](https://forum.ansible.com/t/remote-user-var-persists-between-plays/19817/5 "2015-11-20T22:33:26Z")

</div>

Ok. That works:

`
