Resource collectors
Resource collectors select a group of resources by searching the attributes of each resource in the catalog, even resources which haven’t yet been declared at the time the collector is written. Collectors realize virtual resources, are used in chaining statements, and override resource attributes. Collectors have an irregular syntax that enables them to function as a statement and a value.
Syntax
User <| title == 'luke' |> # Collect a single user resource whose title is 'luke'
User <| groups == 'admin' |> # Collect any user resource whose list of supplemental groups includes 'admin'
Yumrepo['custom_packages'] -> Package <| tag == 'custom' |> # Creates an order relationship with several package resources
The
general form of a resource collector is: -
A capitalized resource type name. This cannot be
Class
, and there is no way to collect classes. -
<|
- An opening angle bracket (less-than sign) and pipe character. -
Optionally, a search expression.
-
|>
- A pipe character and closing angle bracket (greater-than sign)
Using a special expression syntax, collectors search the values of resource titles and attributes. This resembles the normal syntax for Puppet expressions, but is not the same.
Package <| provider == yum |>
collects only
packages whose provider
attribute is explicitly set
to yum
in the manifests. It does not match packages
that would default to the yum
provider based on the
state of the target system.and
and or
operators.
You can create complex expressions using four operators. -
==
(equality search) - This operator is non-symmetric:
-
The left operand (attribute) is a string, and must be the name of a resource attribute or the word
title
(which searches on the resource’s title). If the resource attribute name is a reserved word (for example,site
,unit
, orapplication
), it must be in quotes. -
The right operand (search key) must be a string, boolean, number, resource reference, or undef. The behavior of arrays and hashes in the right operand is undefined in this version of Puppet.
-
-
!=
(non-equality search) - This operator is non-symmetric:
-
The left operand (attribute) is a string, and must be the name of a resource attribute or the word
title
(which searches on the resource’s title). If the resource attribute name is a reserved word (for example,site
,unit
, orapplication
), it must be in quotes. -
The right operand (search key) must be a string, boolean, number, resource reference, or undef. The behavior of arrays and hashes in the right operand is undefined in this version of Puppet.
-
-
and
- Both operands must be valid search expressions. For a given resource, this
operator matches if both of the operands match for that resource. This operator
has higher priority than
or
. -
or
- Both operands must be valid search expressions. For a given resource, this
operator matches if either of the operands match for that resource. This
operator has lower priority than
and
.
Location
Use resource collectors in a collector attribute block for amending resource attributes, or as the operand of a chaining statement, or as independent statements.
-
As the value of a resource attribute
-
As the argument of a function
-
Within an array or hash
-
As the operand of an expression other than a chaining statement
query_resources
function of the
puppetdb_query
module returns an array of resources.
For more information, see PuppetDB query tools.Behavior
A resource collector realizes any virtual resources matching its search expression. Empty search expressions match every resource of the specified resource type.
-
In a chaining statement, a collector acts as a proxy for every resource (virtual or not) that matches its search expression.
-
When given a block of attributes and values, a collector sets and overrides those attributes for every resource (virtual or not) matching its search expression.
Exported resource collectors
An exported resource collector uses a modified syntax that realizes exported resources and imports resources published by other nodes.
To use exported resource collectors, enable catalog storage and searching (storeconfigs
). See Exported resources for more details. To
enable exported resources, follow the installation instructions and Puppet configuration instructions in the PuppetDB docs.
Like normal collectors, use exported resource collectors with attribute blocks and chaining statements.
Nagios_service <<| |>> # realize all exported nagios_service resources
The
general form of an exported resource collector is: -
The resource type name, capitalized.
-
<<|
— Two opening angle brackets (less-than signs) and a pipe character. -
Optionally, a search expression.
-
|>>
— A pipe character and two closing angle brackets (greater-than signs).