Use a regular expression in lookup_options
You can use regular expressions in lookup_options to configure merge behavior for many
lookup keys at the same time.
A regular expression
key such as '^profile::(.*)::users$' sets the merge behavior for profile::server::users,
profile::postgresql::users, profile::jenkins::server::users. Regular expression lookup options use
Puppet’s regular expression support, which is
based on Ruby’s regular expressions.
To use a regular expression in lookup_options:
- Write the pattern as a quoted string. Do not use
the Puppet language’s forward-slash
(/.../)regular expression delimiters. - Begin the pattern with the start-of-line
metacharacter (
^, also called a carat). If ^ isn’t the first character, Hiera treats it as a literal key name instead of a regular expression. - If this data source is in a module, follow
^with the module’s namespace: its full name, plus the::namespace separator. For example, all regular expression lookup options in thentpmodule must start with^ntp::. Starting with anything else results in an error.
The merge behavior you set for that pattern applies to all lookup keys that match it. In cases where multiple lookup options could apply to the same key, Hiera resolves the conflict. For example, if there’s a literal (not regular expression) option available, Hiera uses it. Otherwise, Hiera uses the first regular expression that matches the lookup key, using the order in which they appear in the module code.
lookup_options
are assembled with a hash merge, which puts keys from lower priority data
sources before those from higher priority sources. To override a module’s
regular expression configured merge behavior, use the exact same regular
expression string in your environment data, so that it replaces the module’s
value. A slightly different regular expression won’t work because the
lower-priority regular expression goes first.