remote_user var persists between plays?

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:

`

This: 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

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.

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

Ok. That works:

`