Normally, I can specify the host filter to exclude the specific host in API as below:
http://<AWX_URL>/api/v2/hosts/?not__name__icontains=test
But when I created the smart inventory, we cannot specify the not.name.icontains:test filter.
Is it the normal behavior of smart inventory? Is there any way to exclude the specific host on smart inventory?
not.name.icontains:test3 but it shows No records matched your search.."test1" and "test2" will appear on smart inventory.
No records matched.
I spent a few moments looking into this one. I don't think that operators other than equal are supported by the api when specifying a host filter on a smart inventory. Additionally, the UI doesn't currently support any keys that come before the field in any capacity. For example, in a regular (non host filter) search something like not.name:foo is not currently supported by the UI. In this case, the field would be name and since not comes before it, it's not currently supported. The UI will convert that to ?search=not.name:foo which is generally not useful.
There are two things that would need to happen in order to support this:
1) The api would need to add support for operators other than equal wrt the smart inventory host filter so that POSTing something like:
{
"name": "test inv",
"description": "",
"organization": 1,
"kind": "smart",
"host_filter": "not__name__icontains=test",
"variables": "",
"insights_credential": null
}
would be valid.
2) The UI will need to add support for operators like or and not which appear before the field in the search string
All that being said, I'd say this is an enhancement to search since none of this was supported in the initial implementation.
How long until this is available in a Tower general release?
Any updates on this please?
This would be doable on "classic" django sort of queries, we support it as a generic filter. Due to performance reasons, it's not possible to support this on ansible facts (json type).
Any plans to add this as a feature? This is a pretty serious deficiency when you can't support simple query constructs like 'not'.
I would be nice to do something like this:
host_filter": "groups__name=group1 and not__name__icontains=xyz"
+1
Any progress on this?
Hey @vvaldez,
Unfortunately, no. If that changes, details will show up in this issue thread.
FYI if anyone wants to take a stab at this here is a braindump.
https://github.com/ansible/awx/blob/devel/awx/main/utils/filters.py#L326 <-- Add a new operator type
class Not(object):
def __init__(self, t):
return Q(~t)
https://github.com/ansible/awx/blob/devel/awx/main/utils/filters.py#L355 <-- Add it as a unary operator
Most helpful comment
Any plans to add this as a feature? This is a pretty serious deficiency when you can't support simple query constructs like 'not'.
I would be nice to do something like this:
host_filter": "groups__name=group1 and not__name__icontains=xyz"