Hi,
I have two testing environments, located in different regions. Within each of those environments, among all the servers, there is a monitoring server. In one of my ansible roles I would like to be able to select the ip address of the relevant monitoring server. I thought that I could use a combination of hostvars, intersect and the relevant groups to be able to select the right server. An example of what I currently have is as follows:
hostvars[groups[‘test’] | intersect(groups[region]) | intersect(groups[‘monitoring_server’]) | first].rax_addresses[network_name][0].addr
In the above example, the variable ‘region’ could either be GIB, or LON. The 2 monitoring servers each exist in the test group and the monitoring_server group. They then each exist in a group which reflects the region they serve.
I am expecting hostvars to return just one of the two servers - the one that is in all three of the groups. However, at the moment both servers are being returned.
Have I misinterpreted how the intersect should work, or am I doing it wrong? Are there other ways to achieve what I’m attempting to do here?
Thanks!
Dan.