-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query filter and smart inventory; host membership of indirect group #1258
Comments
@bartmeuris just a thought, but could you try |
@bartmeuris the host_filter is primarily for filtering host facts, and so for your query for groups, you probably don't need the host_filter, and can query the host endpoint directly. So |
@jaredevantabor the problem isn't that This is also an issue with Smart Inventories, which is how I bumped into the issue, but since this also had this issue when using the API, I would expect the problem to be the same. |
Querying the API for group membership must be done with the tree structure in mind. Note that the above query will only work for hosts that exist in a group 1 level below dnsservers. |
Ok, the This is very confusing however, I would expect hosts from sub-groups to be included in the parent. This also has the problem that this works for hosts in sub-groups, but would not include any hosts included directly in the I can use Now this non-listing of sub-group member hosts is weird and counter-intuitive, but I suspect that when AWX/Tower expects it to work this way, changing this could have a serious impact and changing this behavior would be a no-go. Fixing the Smart Inventory UI to allow for However, after some searching, there seems to be an
As expected, this also doesn't work using the smart inventories, since they use the same filtering. The documentation however states (emphasis is mine):
My interpretation here is that this should be query-able, but isn't If this would be, this would be the best solution in my opinion. This would mean I would be able to filter in the smart inventory using |
@bartmeuris You've understood the general design of the API filtering well. However, not all fields that we show are queriable. Manifested fields are not queriable.
awx/awx/main/models/inventory.py Line 930 in 1582fcb
awx/awx/main/models/inventory.py Line 634 in 1582fcb
To your point that arbitrary nested host group membership is not queriable. This is not easy when thinking about a relational database. The group -> group -> ... -> host relationships are stored as foreign keys. If you have So you can see, there is no direct relationship from We could solve this problem by (1) creating a link from every host to every group that it's in. This would require a pretty pricey update anytime the inventory topology changes or (2) upon viewing a particular group's host list, we can compute that host list. I think we can make (2) queriable since it returns a |
@chrismeyersfsu yes I already dove into the code and had pinpointed it to that Glad to hear this could possibly be solved, I currently know the limitations, so I can work with this, and for my smart inventories use the API to fix the |
Postgres |
We are moving away from smart inventories and recently introduced a new feature called Constructed Inventory. That merged in #13448 and got released with AWX 22. Constructed Inventories allow for querying host vars. I'm going to go ahead and close this and can also follow up with a link to a blog post that @AlanCoding is currently working on. Docs to new constructed inventory source: https://github.com/ansible/awx/blob/devel/docs/inventory/constructed_inventory.md |
ISSUE TYPE
COMPONENT NAME
SUMMARY
Nested groups cannot be found using
host_filter
API or smart inventories.ENVIRONMENT
STEPS TO REPRODUCE
Preparation: create groups:
dnsservers
dns-authoritative
anddns-recursive
dns-authoritative
anddns-recursive
groups, and none directly in thednsservers
group.Using the API, go to:
/api/v2/hosts/?host_filter=groups__name=dnsservers
EXPECTED RESULTS
Expected results are that when searching for
dnsservers
would return all hosts in both thedns-authoritative
anddns-recursive
groups.ACTUAL RESULTS
Actual result is that an empty result is returned:
Both the
/api/v2/hosts/?host_filter=groups__name=dns-authoritative
and/api/v2/hosts/?host_filter=groups__name=dns-recursive
requests do return the expected hosts in those groups.ADDITIONAL INFORMATION
dnsservers
group, and look at the hosts there, you do see all hosts I would expect to be returned./api/v2/hosts/?groups__search=
does not make any difference.dns-authoritative
ordns-recursive
works, butdnsservers
results in an empty result.The text was updated successfully, but these errors were encountered: