# getting facts from previous plays

**URL:** <https://forum.ansible.com/t/getting-facts-from-previous-plays/12172>\
**Category:** Ansible Project\
**Created:** [December 29, 2012, 9:03pm UTC](https://forum.ansible.com/t/getting-facts-from-previous-plays/12172 "2012-12-29T21:03:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://forum.ansible.com/u/James_Martin)\
**Post date:** [December 29, 2012, 9:03pm UTC](https://forum.ansible.com/t/getting-facts-from-previous-plays/12172/1 "2012-12-29T21:03:36Z")

</div>

I’m a bit confused by the wording here:

“The hosts that you want to reference data from must be included in either the current play or any previous play”

Does that mean of any playbook, or just the same playbook?

Thanks,

James

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [December 29, 2012, 9:22pm UTC](https://forum.ansible.com/t/getting-facts-from-previous-plays/12172/2 "2012-12-29T21:22:50Z")

</div>

Playbooks contain (rather, ARE) lists of plays, and can include other  
playbooks. Thus anything that has a "hosts:" is it's own play, and a  
playbook can include more than one of those.

So when it says plays, it means plays, not playbooks.

If the play has been executed, those facts gathered in that play are  
available to subsequently executed plays.

---

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://forum.ansible.com/u/James_Martin)\
**Post date:** [December 29, 2012, 9:54pm UTC](https://forum.ansible.com/t/getting-facts-from-previous-plays/12172/3 "2012-12-29T21:54:43Z")

</div>

Thanks for clearing this up for me. Makes sense now.

James

---

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://forum.ansible.com/u/James_Martin)\
**Post date:** [December 30, 2012, 10:01pm UTC](https://forum.ansible.com/t/getting-facts-from-previous-plays/12172/4 "2012-12-30T22:01:08Z")

</div>

Does what you say hold true for custom facts too? This doesn’t appear to be true in my playbook: [https://gist.github.com/4415483](https://gist.github.com/4415483).

$mypackage\_url is returned properly on the first play, but on the second play it includes nothing.

Thanks for your help,

James

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [December 31, 2012, 11:46am UTC](https://forum.ansible.com/t/getting-facts-from-previous-plays/12172/5 "2012-12-31T11:46:13Z")

</div>

James Martin wrote:

> Does what you say hold true for custom facts too? This doesn't appear to  
> be true in my playbook: [https://gist.github.com/4415483](https://gist.github.com/4415483).  
> $mypackage\_url is returned properly on the first play, but on the second  
> play it includes nothing.
> 
> Thanks for your help,

The local connection type uses the hostname 127.0.0.1.  
${hostvars.{127.0.0.1}.mypackage\_url} should work.

Daniel

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [December 31, 2012, 2:30pm UTC](https://forum.ansible.com/t/getting-facts-from-previous-plays/12172/6 "2012-12-31T14:30:28Z")

</div>

> The local connection type uses the hostname 127.0.0.1.  
> ${hostvars.{127.0.0.1}.mypackage\_url} should work.

I still maintain that syntax is pretty hard to read.

I think we should allow usage of Jinja2 in playbooks again.
