# Passing a fact to another play

**URL:** <https://forum.ansible.com/t/passing-a-fact-to-another-play/23795>\
**Category:** Ansible Project\
**Created:** [February 22, 2017, 9:50am UTC](https://forum.ansible.com/t/passing-a-fact-to-another-play/23795 "2017-02-22T09:50:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![barnaclefluff](https://avatars.discourse-cdn.com/v4/letter/b/8edcca/32.png) [@barnaclefluff](https://forum.ansible.com/u/barnaclefluff)\
**Post date:** [February 22, 2017, 9:50am UTC](https://forum.ansible.com/t/passing-a-fact-to-another-play/23795/1 "2017-02-22T09:50:51Z")

</div>

Imagine I have multiple hadoop clusters, each with a master node and a varying amount of slave nodes connected to it.  
I want to dynamically discover the slaves from the master, and then perform actions on them in serial mode (only impact one node at a time to minimize downtime).

What’s the right way to do this?

An almost-working approach is below, but I have a problem at “xxxxx”. If I hardcode a master node name there, everything works. But I don’t want to since that’s silly and  
there are lots of clusters. But I don’t know how I can pass the master node name across the plays?

- hosts : hadoop\_master\_nodes # run this on all master nodes  
tasks:

- name: find targets  
shell: list\_all\_my\_hadoop\_nodes.sh # show list of nodes connected to this master  
register: target\_nodes

- set\_fact:  
target\_nodes: “{{ target\_nodes.stdout\_lines }}” # set a fact so we can call it from the next step

- hosts: “{{ hostvars[‘xxxxxxxx’][‘target\_nodes’] }}” # call the list of target\_nodes discovered above  
serial: 1  
tasks:

- name: do whatever # “do whatever” one at a time across all the target nodes  
…

---

<div class="post-metadata">

**Author:** ![Pieter\_Voet](https://avatars.discourse-cdn.com/v4/letter/p/5fc32e/32.png) [@Pieter\_Voet](https://forum.ansible.com/u/Pieter_Voet)\
**Post date:** [February 22, 2017, 11:26am UTC](https://forum.ansible.com/t/passing-a-fact-to-another-play/23795/2 "2017-02-22T11:26:07Z")

</div>

Hi,

this scenario looks like the one I addressed in my pull request : [https://github.com/ansible/ansible/pull/20849](https://github.com/ansible/ansible/pull/20849)

Passing the ‘xxxxx’ value as an ‘–extra-var’ value is an option, but still requires the value to be known upfront  
and hence will not solve your problem.  
That’s why I created a module where a play can set an ‘extra variable’ with a runtime discovered value. Since the  
‘extra variable’ is accessible thru all plays, this is a way to pass information between plays.

The pull request is waiting on community review, so if you like, go ahead…

Pieter.

---

<div class="post-metadata">

**Author:** ![barnaclefluff](https://avatars.discourse-cdn.com/v4/letter/b/8edcca/32.png) [@barnaclefluff](https://forum.ansible.com/u/barnaclefluff)\
**Post date:** [February 22, 2017, 8:38pm UTC](https://forum.ansible.com/t/passing-a-fact-to-another-play/23795/3 "2017-02-22T20:38:25Z")

</div>

Cool, I’ll take a look at that. In the meantime I think I have found a workaround, using add\_host to create a group and then using that in my second hosts: bit. Seems to work, though it feels hackey.
