Using Foreman/Katello 3.3/4.5 and when I perform searches using the != together with host collections it seems the search just ignores it. I assume the != is a way to filter out things from the search result like:
host_collection != centos7
would give me a search result of hosts that does not below to the centos7 host collection, but it does not. It gives me all hosts.
If I do:
host_collection = centos7
It works as expected and returns me a lists if host in the centos7 host collection.
It seems that
host_collection != will only return hosts that belong to at least one host collection (but not the specified one.) I agree this is strange, but it may just be the way that scoped_search works. Can you confirm if this is the case for you?
All my hosts belong to at least one host collection. Some belong to more then one.
I actually did some more testing and it turns out you can do a search like this:
NOT host_collection = centos7
This returns the result I am looking for.
Well, that is true for all hosts which have a host_collection assigned which is not called “centos7”. As host_collection is effectively an array of names, I don’t see any other way to interpret that: it’s true if a value in the array exists which is not “centos7”.
As you have found out, using
not inverts the original condition which is what you wanted.
This “problem” is very often there because many attributes to search for are array, e.g. search for content hosts having a particular package installed is
installed_package_name = coreutils but
installed_package_name != coreutils is not the same as
not installed_package_name = coreutils…