# Can somebody help me understand hostvars and jinja's intersect?

**URL:** <https://forum.ansible.com/t/can-somebody-help-me-understand-hostvars-and-jinjas-intersect/23054>\
**Category:** Ansible Project\
**Created:** [November 18, 2016, 1:44pm UTC](https://forum.ansible.com/t/can-somebody-help-me-understand-hostvars-and-jinjas-intersect/23054 "2016-11-18T13:44:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [November 18, 2016, 1:44pm UTC](https://forum.ansible.com/t/can-somebody-help-me-understand-hostvars-and-jinjas-intersect/23054/1 "2016-11-18T13:44:29Z")

</div>

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.
