# Searching, smart inventories and facts

**URL:** <https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578>\
**Category:** AWX Project\
**Created:** [September 14, 2018, 6:21pm UTC](https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578 "2018-09-14T18:21:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmakovey](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dmakovey](https://forum.ansible.com/u/dmakovey)\
**Post date:** [September 14, 2018, 6:21pm UTC](https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578/1 "2018-09-14T18:21:16Z")

</div>

I’m trying to create smart inventory based on facts that ansible has already collected, however any of the searches I construct result either in empty set or deemed to be broken by Tower. Some sample searches:

ansible\_facts.osfamily:RedHat

ansible\_facts.osfamily:=RedHat

variables.osfamily:RedHat  
ansible\_variables.osfamily:RedHat

---

<div class="post-metadata">

**Author:** ![dmakovey](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dmakovey](https://forum.ansible.com/u/dmakovey)\
**Post date:** [September 14, 2018, 6:30pm UTC](https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578/2 "2018-09-14T18:30:43Z")

</div>

another note: I don't have facts caching, but browsing API I can see  
values of interest in "variables" which seems to be an escaped JSON  
string, so I'm not 100% sure how to un-escape it for search.

---

<div class="post-metadata">

**Author:** ![Sujith\_A\_R1](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sujith\_A\_R1](https://forum.ansible.com/u/Sujith_A_R1)\
**Post date:** [September 14, 2018, 6:52pm UTC](https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578/3 "2018-09-14T18:52:09Z")

</div>

I couldn’t get the exact API where I can use it for collecting each variable information for each hosts. However, you can create filter something like this to get Linux VM’s through smart inventory by choosing the key information as ’ variables:linux ’

---

<div class="post-metadata">

**Author:** ![dmakovey](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dmakovey](https://forum.ansible.com/u/dmakovey)\
**Post date:** [September 14, 2018, 6:55pm UTC](https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578/4 "2018-09-14T18:55:40Z")

</div>

> I couldn't get the exact API where I can use it for collecting each  
> variable information for each hosts. However, you can create filter  
> something like this to get Linux VM's through smart inventory by  
> choosing the key information as ' variables:linux '

just tried:

variables:RedHat

0 results, which is impossible as my entire fleet has 'osfamily:RedHat'  
in variables. I'm definitely not using things right but which ones and  
how should I use them? Documentation is rather scarce on subject.

---

<div class="post-metadata">

**Author:** ![Sujith\_A\_R](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@Sujith\_A\_R](https://forum.ansible.com/u/Sujith_A_R)\
**Post date:** [September 14, 2018, 7:07pm UTC](https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578/5 "2018-09-14T19:07:01Z")

</div>

Those values should be exist under variables json inorder to work.

If filtering works for finding Linux VM’S through the key as ‘variables:linux’ instead of Redhat, we can have our playbook to point out only to the Redhat mahines where the play should run. That can be easily mapped through ‘when’ statement using role based deployment . But, that’s another work around by going through an extra step since couldnt get a API call to filter out each objects under varaiables json.

---

<div class="post-metadata">

**Author:** ![dmakovey](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dmakovey](https://forum.ansible.com/u/dmakovey)\
**Post date:** [September 14, 2018, 7:11pm UTC](https://forum.ansible.com/t/searching-smart-inventories-and-facts/28578/6 "2018-09-14T19:11:18Z")

</div>

osfamily:RedHat has been used as an example in my case. I have other  
custom facts that should work in a similar fashion but do not. So, to  
recap: searching for very standard "osfamily:RedHat" produces no result,  
neither is search for some "custom\_fact:custom\_value" . I have been  
working around this in playbook with when clause, but that means that  
"Smart Inventories" are a broken feature for me (or I'm not educated  
enough to use it).
