-
Notifications
You must be signed in to change notification settings - Fork 42
Filters
Note: Broker's filters will be radically changing in Broker 0.3
Broker's inventory filters are based on what is stored in its local inventory file. Therefore, only properties in that file are filterable. Nested properties are annotated with a .
notation. For example, a top-level property hostname
can be accessed by itself. However, a nested property of _broker_args
called version
would be accessed by _broker_args.version
.
This type of filter is used against the output of some of Broker's commands where a list of results is passed in. The filter will be matched against each item in the list and only those matching the filter will be returned.
Filters are any valid python expression that acts upon a filterable object. A filterable object is a list typically noted with either @inv
or @res
. Broker will replace that notation, in the filter expression, with a valid list whose contents are context-dependent.
--filter '"test" in @inv.hostname'
The string "test" exists somewhere in the hostname value
--filter '@inv[-1]'
Use the last host in the inventory
--filter '@inv[3:7]'
Pick the 4th through 7th hosts in the inventory
--filter '@inv._broker_args.template.startswith("deploy-sat")'
The template should start with the string "deploy-sat"
You can also chain multiple filters together, feeding the results of the previous filter into the next, using the pipe |
symbol. This allows you to perform multiple layers of filtering in a single expression.
--filter '"test" in @inv.name | @inv._broker_args.provider != "RHV"'
The host's name should have test in it and the provider should not equal RHV.
--results-filter '"test" in @res'
The string "test" exists in the results item
--results-filter '@res[-1]'
Return just the last item from the results list
Note: Due to shell expansion, it is recommended to wrap a filter in single quotes.