# using gathered fact in another play in the same playbook

**URL:** <https://forum.ansible.com/t/using-gathered-fact-in-another-play-in-the-same-playbook/15823>\
**Category:** Ansible Developer\
**Created:** [July 31, 2014, 4:28pm UTC](https://forum.ansible.com/t/using-gathered-fact-in-another-play-in-the-same-playbook/15823 "2014-07-31T16:28:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene\_Dementiev](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Eugene\_Dementiev](https://forum.ansible.com/u/Eugene_Dementiev)\
**Post date:** [July 31, 2014, 4:28pm UTC](https://forum.ansible.com/t/using-gathered-fact-in-another-play-in-the-same-playbook/15823/1 "2014-07-31T16:28:36Z")

</div>

Hi all!

Let’s say I have a few hosts (a.local, b.local) with postgresql installed, and I want to add them to bacula system on a backup host (backup.local).  
Basically, each database host would have have a file named {{ hostname }}.conf with the following:

---

<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:** [July 31, 2014, 4:58pm UTC](https://forum.ansible.com/t/using-gathered-fact-in-another-play-in-the-same-playbook/15823/2 "2014-07-31T16:58:04Z")

</div>

1. Extra vars are totally available between plays.

2. Yes, you can get to variables registered for other systems through hostvars:

{{ hostvars[your\_hostname\_here][variable\_here] }}

---

<div class="post-metadata">

**Author:** ![Eugene\_Dementiev](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Eugene\_Dementiev](https://forum.ansible.com/u/Eugene_Dementiev)\
**Post date:** [July 31, 2014, 5:38pm UTC](https://forum.ansible.com/t/using-gathered-fact-in-another-play-in-the-same-playbook/15823/3 "2014-07-31T17:38:24Z")

</div>

Thanks! #2 is what I wanted!

I’ve written a small discovery script:

`  
#!/bin/sh

for path in “$@”  
do  
if [-d “$path”] || [-f “$path”]  
then  
echo -n “$path”  
exit 0  
fi  
done  
exit 1  
`

And use it:

`

- hosts: {{ hostname }}  
tasks:

- name: discover  
script: “discover.sh ‘/tmp’ ‘/etc’”  
register: pgdir

- hosts: bacula.local  
tasks:

- debug: msg=“{{ hostvars[hostname][‘pgdir’][‘stdout’] }}”

`

But can I use extra var “hostname” and NOT add it to /etc/ansible/hosts ?

p.s. there probably should be a module to discover remote paths, how do you think?
