# Inventories/Groups

**URL:** <https://forum.ansible.com/t/inventories-groups/35795>\
**Category:** AWX Project\
**Tags:** aws, awx\
**Created:** [September 28, 2021, 7:47pm UTC](https://forum.ansible.com/t/inventories-groups/35795 "2021-09-28T19:47:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony1](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tony1](https://forum.ansible.com/u/Tony1)\
**Post date:** [September 28, 2021, 7:47pm UTC](https://forum.ansible.com/t/inventories-groups/35795/1 "2021-09-28T19:47:50Z")

</div>

This may seem a bit obvious, but I am struggling to work out how to handle some things with AWX Inventories.

All my hosts are sync’d from AWS.

Example

Host1 (Inventory: DEV-eu-west-1)  
Host2 (Inventory: STAGE-eu-west-1)  
Host3 (Inventory: TEST-eu-west-1)  
Host4 (Inventory: PROD-eu-west-1)

I want to be able to run a template against each inventory, and also ALL inventories.

I thought “Groups” would do this, but it doesn’t show existing groups when I add.

Any help anyone?

Cheers

---

<div class="post-metadata">

**Author:** ![Christopher\_Meyers](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Christopher\_Meyers](https://forum.ansible.com/u/Christopher_Meyers)\
**Post date:** [September 28, 2021, 9:42pm UTC](https://forum.ansible.com/t/inventories-groups/35795/2 "2021-09-28T21:42:52Z")

</div>

The smart inventory feature lets you create an inventory from hosts that exist in multiple inventories.

---

<div class="post-metadata">

**Author:** ![Tony1](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tony1](https://forum.ansible.com/u/Tony1)\
**Post date:** [September 30, 2021, 1:34pm UTC](https://forum.ansible.com/t/inventories-groups/35795/3 "2021-09-30T13:34:04Z")

</div>

Hey Chris,

Any pointers on how I get this working on AWX v19?

I’m trying to filter out hosts with specific custom facts.

Lets use all CentOS hosts for example.

Cheers

---

<div class="post-metadata">

**Author:** ![Tony1](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tony1](https://forum.ansible.com/u/Tony1)\
**Post date:** [September 30, 2021, 1:40pm UTC](https://forum.ansible.com/t/inventories-groups/35795/4 "2021-09-30T13:40:36Z")

</div>

Bit more info. I’m doing an advanced filter, but it doesn’t make much sense to me

This is the fact i’m trying to filter on:

“ansible\_distribution”: “CentOS”

Cheers

> **(attachments)**
>
> ![filter.PNG](https://us1.discourse-cdn.com/ansible/optimized/2X/5/53e2d5fb1b1b7b2895a4f6b44aeb31ece8dc78c5_2_690x59.png)

---

<div class="post-metadata">

**Author:** ![Christopher\_Meyers](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Christopher\_Meyers](https://forum.ansible.com/u/Christopher_Meyers)\
**Post date:** [September 30, 2021, 1:44pm UTC](https://forum.ansible.com/t/inventories-groups/35795/5 "2021-09-30T13:44:35Z")

</div>

Filtering out hosts by ansible\_facts that do match some condition is tricky from an implementation perspective. We would need to ensure that the GIN index that we use in Postgres is still being used. That is one of the reasons this feature doesn’t exist in AWX today.

I use the API directly when I’m constructing host\_filter. You can “test” your host filter on the /api/v2/hosts/ endpoint. When you have what you want you can use the API to save that filter i.e. navigate to the browsable API via /api/v2/inventories/3/ change the json host\_filter value to whatever you have crafted and click PATCH.

/api/v2/hosts?host\_filter=ansible\_facts\_\_ansible\_distribution=CentOS \<— this would create an inventory WITH CentOS hosts.

---

<div class="post-metadata">

**Author:** ![Tony1](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tony1](https://forum.ansible.com/u/Tony1)\
**Post date:** [September 30, 2021, 2:07pm UTC](https://forum.ansible.com/t/inventories-groups/35795/6 "2021-09-30T14:07:34Z")

</div>

Cheers, so just so I am clear

Create a standard inventory

Locate and browse to the inventory via the API - in my case ID 20

Within content, change the hostfilter value:

My case:

{  
“name”: “test”,  
“description”: “test”,  
“organization”: 1,  
“kind”: “”,  
“host\_filter”: “ansible\_facts\_\_ansible\_distribution=CentOS”,  
“variables”: “—”  
}

Is that correct?

---

<div class="post-metadata">

**Author:** ![Tony1](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tony1](https://forum.ansible.com/u/Tony1)\
**Post date:** [September 30, 2021, 2:24pm UTC](https://forum.ansible.com/t/inventories-groups/35795/7 "2021-09-30T14:24:14Z")

</div>

Ah got it working, I had to create a dummy smart inventory, then make the changes above.

Thanks very much Chris, really appreciate it.
