# Variables across nodes

**URL:** <https://forum.ansible.com/t/variables-across-nodes/14202>\
**Category:** Ansible Project\
**Created:** [December 21, 2013, 7:46pm UTC](https://forum.ansible.com/t/variables-across-nodes/14202 "2013-12-21T19:46:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [December 21, 2013, 7:46pm UTC](https://forum.ansible.com/t/variables-across-nodes/14202/1 "2013-12-21T19:46:01Z")

</div>

I’m trying to build a paybook which will provision 2 compute instances on amazon ec2, and then install mysql on one of them, and apache2/wordpress on the other.

I’m stuck with trying to configure the wordpress instance’s wp-config file which needs to point to the mysql instance. I don’t know the name/ip address of these nodes when the playbook starts, so I’m using the Ansible modules for provisioning them and adding them to their respective host groups after provisioning. I can save the output of the provisioning task as a variable, but this var is not accessible outside of the node which ran the provisioning job.

From any node I can use the “groups[‘tag\_Group\_MySQL’]”, but this only lets me access the instance’s public ip, not the other facts about it.

So, I need to access hostvars of a host which needs to be dynamically assigned. I tried something like {{ hostvars[host][groups[‘tag\_Group\_MySQL’][0]]}} but that doesnt work. I don’t even know if “nested vars” is supported.

Any pointers on how to solve this issue will de deeply appreciated! The current playbook can be found at [https://github.com/trondhindenes/AnsibleTest/tree/master/ec2-env](https://github.com/trondhindenes/AnsibleTest/tree/master/ec2-env)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 23, 2013, 4:59pm UTC](https://forum.ansible.com/t/variables-across-nodes/14202/2 "2013-12-23T16:59:52Z")

</div>

This part:

{{ hostvars[host][groups[‘tag\_Group\_MySQL’][0]] }}

is incorrect.

Try this:

{{ hostvars[groups[‘tag\_Group\_MySQL’][0] ][variable\_name] }}

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [December 27, 2013, 1:03pm UTC](https://forum.ansible.com/t/variables-across-nodes/14202/3 "2013-12-27T13:03:09Z")

</div>

Thanks Michael,

Just out of curiosity, I can’t seem to find this type of info in the documentation. Is it in there somewhere?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 29, 2013, 2:32pm UTC](https://forum.ansible.com/t/variables-across-nodes/14202/4 "2013-12-29T14:32:46Z")

</div>

It’s in the latest FAQ, though it’s not pushed to the website just yet.

(This is waiting for about a week for some other reasons)
