Inventories/Groups

,

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

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

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

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

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.

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?

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

Thanks very much Chris, really appreciate it.