# Vars and register passing on to include playbooks

**URL:** <https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496>\
**Category:** Ansible Project\
**Created:** [May 19, 2016, 8:12pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496 "2016-05-19T20:12:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Louthan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Joe\_Louthan](https://forum.ansible.com/u/Joe_Louthan)\
**Post date:** [May 19, 2016, 8:12pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/1 "2016-05-19T20:12:15Z")

</div>

By all accounts that I can see, the following should work:

`

---

<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:** [May 20, 2016, 12:49pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/2 "2016-05-20T12:49:12Z")

</div>

So vars seems to be incorrectly indented, also you should not need to add ‘bash’ to command

The registered var should persist but it is available only through the server01 host.

---

<div class="post-metadata">

**Author:** ![Joe\_Louthan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Joe\_Louthan](https://forum.ansible.com/u/Joe_Louthan)\
**Post date:** [May 20, 2016, 1:03pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/3 "2016-05-20T13:03:45Z")

</div>

indented var: that is a copy/paste mistake.

So those vars and register will not persist to any of the other include playbooks?

---

<div class="post-metadata">

**Author:** ![Joe\_Louthan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Joe\_Louthan](https://forum.ansible.com/u/Joe_Louthan)\
**Post date:** [May 20, 2016, 1:04pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/4 "2016-05-20T13:04:41Z")

</div>

`

---

<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:** [May 20, 2016, 1:30pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/5 "2016-05-20T13:30:41Z")

</div>

vars don’t they are play specific, host vars (facts and registered vars) do persist, but they are associated to the specific host.

So in subsequent plays you might need to do hostvars[‘server01’][‘timestamp’] to get the var if they are not also targetting server01.

---

<div class="post-metadata">

**Author:** ![Joe\_Louthan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Joe\_Louthan](https://forum.ansible.com/u/Joe_Louthan)\
**Post date:** [May 20, 2016, 1:48pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/6 "2016-05-20T13:48:38Z")

</div>

So in order to access this var/register from server01, I could do something like in playbook-01.yml:

`

---

<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:** [May 20, 2016, 1:56pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/7 "2016-05-20T13:56:27Z")

</div>

hostvars are not accessible at the play level, but should be accessible within the play.

---

<div class="post-metadata">

**Author:** ![Joe\_Louthan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Joe\_Louthan](https://forum.ansible.com/u/Joe_Louthan)\
**Post date:** [May 20, 2016, 2:31pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/8 "2016-05-20T14:31:35Z")

</div>

When I do this:  
{{ hostvars[‘server1’][‘timestamp.stdout’] }}

as in:

- name: “Backup {{ proddbname }} Database”  
mysql\_db: “state=dump name={{ proddbname }} target={{ homedir }}{{ proddbname }}{{ hostvars[‘server01’][‘timestamp.stdout’] }}.sql.gz”

It gives me the error  
fatal: [proddbhost]: FAILED! =\> {“failed”: true, “msg”: “‘dict object’ has no attribute ‘timestamp.stdout’”}

---

<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:** [May 20, 2016, 4:56pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/9 "2016-05-20T16:56:05Z")

</div>

you are mixing notations

{{ hostvars[‘server1’][‘timestamp’][‘stdout’] }}

---

<div class="post-metadata">

**Author:** ![Joe\_Louthan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Joe\_Louthan](https://forum.ansible.com/u/Joe_Louthan)\
**Post date:** [May 20, 2016, 6:16pm UTC](https://forum.ansible.com/t/vars-and-register-passing-on-to-include-playbooks/21496/10 "2016-05-20T18:16:49Z")

</div>

DING! That worked. Thank you so much!
