|
In order to be able to filter or modify a value bound at a lower precedence in ways that the built in hiera interpolation or aliasing features can handle it is of great value to be able to lookup the value that would be the result of lower precedence entries and return that.
This mechanism should be available via the $context object via a lookup_below(key). This method takes a no args lambda that is called if the lookup results in not_found. If no lambda is given and the lookup_below(key) results in not_found that also becomes the result of the function calling lookup_below (it does not return to it).
The rest of the arguments to the lookup_below are the same as for a lookup.
As an example a user may do something like this for the lookup of key
return "some prefix: #{context.lookup_below(key)"
|
Without the lookup_below feature this is impossible since a lookup of the same key would lead to an endless recursion and hiera would error out.
This mechanism can thus be used to implement filter/map like behavior, change the data type etc. As an example, a function could filter all "password" keys to wrap them as Sensitive values, a lookup of a hash 'x', could add entries to that hash that comes from other keys, and other similar advanced cases.
|