# How access variable from one playbook in the other playbook?

**URL:** <https://forum.ansible.com/t/how-access-variable-from-one-playbook-in-the-other-playbook/17756>\
**Category:** Ansible Project\
**Created:** [March 16, 2015, 5:52pm UTC](https://forum.ansible.com/t/how-access-variable-from-one-playbook-in-the-other-playbook/17756 "2015-03-16T17:52:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Shuklin](https://avatars.discourse-cdn.com/v4/letter/g/ed8c4c/32.png) [@George\_Shuklin](https://forum.ansible.com/u/George_Shuklin)\
**Post date:** [March 16, 2015, 5:52pm UTC](https://forum.ansible.com/t/how-access-variable-from-one-playbook-in-the-other-playbook/17756/1 "2015-03-16T17:52:28Z")

</div>

Hello.

I'm trying to set up application with database.

My current (simplified) version looks like this:

site.yml:  
- include db.yml  
- include app.yml

db.yml  
- hosts: db  
- roles: foo.install\_db

app.yml  
- hosts: app  
- roles: bar.install\_app

In the group\_var/db I have settings:  
db\_address: '{{ansible\_eth2.address}}'

And I want to use for app:

group\_var/app:  
database\_address: '{{db\_address}}'

But it (non-)obviously does not work.

I've tried to use {{hostvar...}}, but it works with hosts, not with groups.

I feel like I'm doing something strange, but I don't know how to do it right. I need to (in runtime) get ip address of server, based on it group/role, and use it in other role. And this IP can not be hardcoded, because eth2 is not configured by ansible and can be only found in runtime...

Please help, Thanks!

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [March 25, 2015, 12:31pm UTC](https://forum.ansible.com/t/how-access-variable-from-one-playbook-in-the-other-playbook/17756/2 "2015-03-25T12:31:51Z")

</div>

Variable referencing in variable files is not something supported.  
Try referencing the var like this (in the task): hostvars[groups[‘db’][0]].db\_address  
That is for general, cross-groups vars sharing.

But for what you need, you could use hostvars[‘db’].ansible\_eth2.ipv4.address and forget about setting that in var files.

Hope this helps,

Dan.
