# Filter hosts matching groups

**URL:** <https://forum.ansible.com/t/filter-hosts-matching-groups/29488>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [January 22, 2019, 7:00am UTC](https://forum.ansible.com/t/filter-hosts-matching-groups/29488 "2019-01-22T07:00:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruno\_Cochofel](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Bruno\_Cochofel](https://forum.ansible.com/u/Bruno_Cochofel)\
**Post date:** [January 22, 2019, 7:00am UTC](https://forum.ansible.com/t/filter-hosts-matching-groups/29488/1 "2019-01-22T07:00:02Z")

</div>

Hi all,

I have a custom CMDB and I've created a script for dynamic inventory. On that script I have grouped hosts using several ways, just like VMware dynamic inventory script.

My question is, how can I match using more then one group? Something like, I want to deploy to all Linux, that are in the prd group but only the ones that are also in the data center X.  
Is this possible?

Thanks,  
Bruno

---

<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:** [January 22, 2019, 7:36pm UTC](https://forum.ansible.com/t/filter-hosts-matching-groups/29488/2 "2019-01-22T19:36:14Z")

</div>

It shouldn't be a problem check at patterns  
[https://docs.ansible.com/ansible/latest/user\_guide/intro\_patterns.html](https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html)

---

<div class="post-metadata">

**Author:** ![Bruno\_Cochofel](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Bruno\_Cochofel](https://forum.ansible.com/u/Bruno_Cochofel)\
**Post date:** [January 22, 2019, 11:03pm UTC](https://forum.ansible.com/t/filter-hosts-matching-groups/29488/3 "2019-01-22T23:03:01Z")

</div>

Hi,

Thanks Kai, I will give it a try.

Bruno

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [January 23, 2019, 4:37am UTC](https://forum.ansible.com/t/filter-hosts-matching-groups/29488/4 "2019-01-23T04:37:33Z")

</div>

Try this in your playbook

hosts: linux:&prod:&datacenter\_x
