Smart Inventory based on group with children

196 views
Skip to first unread message

Christian Garling

unread,
Jun 23, 2023, 5:01:30 AM6/23/23
to AWX Project
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

AWX Project

unread,
Jun 23, 2023, 1:12:12 PM6/23/23
to AWX Project
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.


Thanks,

AWX Team

Christian Garling

unread,
Jun 26, 2023, 3:37:25 AM6/26/23
to AWX Project
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

Marcus

unread,
Jun 26, 2023, 4:15:23 AM6/26/23
to awx-p...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/cdf81090-3ead-4536-9ebe-02d8ae906a3fn%40googlegroups.com.

AWX Project

unread,
Jun 28, 2023, 2:49:27 PM6/28/23
to AWX Project
Thanks Marcus for providing those instructions! Christian were you able to get it working with constructed inventories?

AWX Team

Christian Garling

unread,
Jul 14, 2023, 7:44:42 AM7/14/23
to AWX Project
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

Reply all
Reply to author
Forward
0 new messages