Variables across nodes

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

This part:

{{ hostvars[host][groups[‘tag_Group_MySQL’][0]] }}

is incorrect.

Try this:

{{ hostvars[ groups[‘tag_Group_MySQL’][0] ][ variable_name ] }}

Thanks Michael,

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

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)