Skip to content

Filters

Jake Callahan edited this page Sep 13, 2024 · 3 revisions

Filters

Note: Broker's filters will be radically changing in Broker 0.3

Inventory Filters

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.

Results Filters

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.

Filter Syntax

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.

Example Filters

Inventory Filters

--filter '"test" in @inv.hosname' 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 3rd through 6th 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 != "RHEV"' The host's name should have test in it and the provider should not equal RHEV.

Results Filters

--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.

Clone this wiki locally