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