# Pattern First after intersection

**URL:** <https://forum.ansible.com/t/pattern-first-after-intersection/22961>\
**Category:** Ansible Project\
**Created:** [November 4, 2016, 4:44pm UTC](https://forum.ansible.com/t/pattern-first-after-intersection/22961 "2016-11-04T16:44:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edgardo\_Vega](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@Edgardo\_Vega](https://forum.ansible.com/u/Edgardo_Vega)\
**Post date:** [November 4, 2016, 4:44pm UTC](https://forum.ansible.com/t/pattern-first-after-intersection/22961/1 "2016-11-04T16:44:41Z")

</div>

I can’t figure out how to create the correct pattern. Currently I am about to get a list of three zookeeper boxes from the pattern **tag\_zookeeper:&tag\_env\_test**.What I need is to get the first (really just any 1) one that results from that list.

Is there any way to do that?

Cheers,

Edgardo

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 4, 2016, 5:15pm UTC](https://forum.ansible.com/t/pattern-first-after-intersection/22961/2 "2016-11-04T17:15:15Z")

</div>

tag\_zookeeper:&tag\_env\_test[0]

---

<div class="post-metadata">

**Author:** ![Edgardo\_Vega](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@Edgardo\_Vega](https://forum.ansible.com/u/Edgardo_Vega)\
**Post date:** [November 4, 2016, 6:23pm UTC](https://forum.ansible.com/t/pattern-first-after-intersection/22961/3 "2016-11-04T18:23:22Z")

</div>

That doesn’t work. That gets the first in the tag\_env\_test group and intersects with the lst of tag\_zookeeper.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 4, 2016, 7:44pm UTC](https://forum.ansible.com/t/pattern-first-after-intersection/22961/4 "2016-11-04T19:44:40Z")

</div>

(lookup(‘inventory\_hostnames’, ‘tag\_zookeeper:&tag\_env\_test’)|list)[0]

---

<div class="post-metadata">

**Author:** ![Edgardo\_Vega](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@Edgardo\_Vega](https://forum.ansible.com/u/Edgardo_Vega)\
**Post date:** [November 6, 2016, 1:18am UTC](https://forum.ansible.com/t/pattern-first-after-intersection/22961/5 "2016-11-06T01:18:40Z")

</div>

That didn’t seem to work in a playbook setting hosts

hosts:(lookup(‘inventory\_hostnames’, ‘tag\_zookeeper:&tag\_env\_test’)|list)[0]

any suggestions?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 7, 2016, 5:08pm UTC](https://forum.ansible.com/t/pattern-first-after-intersection/22961/6 "2016-11-07T17:08:19Z")

</div>

I should have been more explicit:

hosts: “{{(lookup(‘inventory\_hostnames’, ‘tag\_zookeeper:&tag\_env\_test’)|list)[0]}}”
