# Options for filtering hosts

**URL:** <https://forum.ansible.com/t/options-for-filtering-hosts/29504>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [January 23, 2019, 1:40pm UTC](https://forum.ansible.com/t/options-for-filtering-hosts/29504 "2019-01-23T13:40:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_C\_Rigler](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@S\_C\_Rigler](https://forum.ansible.com/u/S_C_Rigler)\
**Post date:** [January 23, 2019, 1:40pm UTC](https://forum.ansible.com/t/options-for-filtering-hosts/29504/1 "2019-01-23T13:40:24Z")

</div>

We have a static inventory where hosts are grouped by location and  
purpose. I was wondering if there was a way to limit a playbook run  
to hosts based on cached facts as a criteria (like only run on rhel 7  
hosts, or only run on virtual hosts, etc). I know I can put the tasks  
in a block with a "when" clause to have it only run on hosts that  
match the criteria, but it still has to iterate through every host to  
decide which to include (which isn't efficient with a large inventory  
where only 10% of the hosts might match the criteria). Any  
suggestions?

Thanks,  
Steve

---

<div class="post-metadata">

**Author:** ![Adam\_E](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Adam\_E](https://forum.ansible.com/u/Adam_E)\
**Post date:** [January 23, 2019, 4:57pm UTC](https://forum.ansible.com/t/options-for-filtering-hosts/29504/2 "2019-01-23T16:57:47Z")

</div>

If you happen to be using awx, you can enable fact caching and then create a dynamic inventory which can be based on search results including facts values
