Smart Inventory based on group with children

Hi there,

I am trying to create a smart inventory based upon the following:

I have a hosts file in INI format with two groups specified as:

[internal:children]
group1
group2

[dmz:children]
group3
group4

I want to use these groups as a smart inventory each, but if I use the name “internal” or “dmz” in the advanced filter as groups__name it does not look up any hosts of the subgroups. How can I achieve this?

Regards, Christian

Hi,

Smart inventories are being deprecated in favor of the new constructed inventory type. I’d recommend trying to utilize that for more advanced query options.

https://github.com/ansible/awx/blob/devel/docs/inventory/constructed_inventory.md

Thanks,

AWX Team

Hi AWX Team,

thanks for your quick response. Actually I dont see, how a constructed inventory can replace a smart inventory.

With smart inventory I can build smaller sub-inventories with for example only NFS or FTP servers in it, based on the groups in my inventory. I have to use groups, because the hostnames unfortunately do not match their function.

With constructed inventories it seems like they always import all hosts and groups found in the inventory file and just can build further groups based on rules. Thats nice, but groups are not visible / selectable in the Template dialog. So the user needs to know the group names or has to find out before he launches a Template. With the smart inventories its much easier, because the user can select one of them directly in the dialog.

Regards, Christian

Hi,
You would need to write extra code to filter for groups.
Use as source the inventory with the groups you want to filter.
i.e. —

plugin: constructed# true means if any of the checks return ‘false’ the whole sync fails
strict: false

might not be necessary

use_extra_vars: true

check if Linux OS

compose:

general check if any of the group name contain certain keywords

linux_group: (group_names | regex_findall(‘.ubuntu.|.redhat.|.rhel.|.debian.|.centos.|.sles.|.suse.|.oraclelinux.|.azure_os_linux.’)) | length >= 1
groups:

create the “filter/limit” group[s] ‘azure_loc_westus2’ comes from the source inventory

az_linux_eastwestus2_patchwave2: ((group_names | intersect([‘azure_loc_westus2’, ‘azure_loc_eastus2’, ‘tag_patchwave_2’])) | length >= 2) and linux_group

You can then limit for ‘az_linux_eastwestus2_patchwave2’

Disadvantage with constructed inventories, at the moment it will duplicate every host that matches, by creating a new host in this new constructed inventory. Even in the same organisation.

Cheers,

Marcus

Thanks Marcus for providing those instructions! Christian were you able to get it working with constructed inventories?

AWX Team

Hi all,

I had to postpone this in favour for another task. I will try it again, when I have the time to do so.

Regards, Christian