Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for a hiera variable syntax which interpolates data by
performing a hiera lookup: [Redmine Ticket](https://projects.puppetlabs.com/issues/21367) This commit adds support for interpolating hiera data in a similar fashion to how scope interpolation functions in hiera. This commit adds the syntax, `%{hiera('foo')}`, for hiera lookups and the syntax, `%{scope('foo')}`, for scope lookups, in order to clearly differentiate the two types. It also retains backward compatibility with the previous syntax for scope lookups, `%{foo}`. Example: ips.yaml potto01_ip: 10.10.1.52 potto01.yaml firewall_rules: - "0.0.0.0:22:%{hiera('potto01_ip')}" When evaluating the string, `"0.0.0.0:22:%{hiera('potto01_ip')}"` hiera would lookup the value for potto01_ip in hiera and interpolate that into the string, the result being, `"0.0.0.0:22:10.10.1.52"`. This avoids having to repeatedly perform this type of lookup logic in puppet and allows you to use your hiera data from within hiera itself.
- Loading branch information
1 parent
981de92
commit 1461832
Showing
4 changed files
with
234 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Allow for safe recursive lookup of values during variable interpolation. | ||
# | ||
# @api private | ||
class Hiera::RecursiveGuard | ||
def initialize | ||
@seen = [] | ||
end | ||
|
||
def check(value, &block) | ||
if @seen.include?(value) | ||
raise Exception, "Interpolation loop detected in [#{@seen.join(', ')}]" | ||
end | ||
@seen.push(value) | ||
ret = yield | ||
@seen.pop | ||
ret | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters