Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hiera lookup single sigil #152

Merged

Conversation

lollipopman
Copy link
Contributor

performing a hiera lookup:

Redmine Ticket

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.

This fixes the backend test if previous tests loaded a backend
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.
@puppetcla
Copy link

CLA signed by all contributors.

# Allow for safe recursive lookup of values during variable interpolation.
#
# @api private
class Hiera::RecursiveGuard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the impetus for changing this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale was two fold:

  1. The previous class was called RecursiveLookup, even though it was not doing recursive lookups, RecursiveGuard is more descriptive as to the intent of the class, i.e. guarding against recursive lookups, rather than performing them.
  2. The previous class performed the scope lookup in the guard, which was confusing and made it difficult to add hiera lookup support.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍, thanks for the explanation. :)

@lollipopman
Copy link
Contributor Author

@adrienthebo I believe I have addressed most of your concerns it the last commits, but I would appreciate any additional feedback you might have.

"test_%{scope('rspec')}_test" => "test_false_test"
}

@intreprets_false_in_scope_tests.each do |input, expected|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: @intreprets -> @interprets :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@adrienthebo
Copy link
Contributor

Thanks for looking at those changes! I've looked this over and I like the general change, but since I missed the error with supporting the old style interpolation syntax last time I would like to get another pair of eyes on this. Thanks again for this contribution!

@lollipopman
Copy link
Contributor Author

@adrienthebo anyone else had a chance to review this pull request?

@zaphod42
Copy link
Contributor

zaphod42 commented Oct 7, 2013

@adrienthebo I just looked it over. I think the test coverage looks good to make sure we aren't regressing on any functionality.

adrienthebo added a commit that referenced this pull request Oct 7, 2013
@adrienthebo adrienthebo merged commit f347bbe into puppetlabs:master Oct 7, 2013
@adrienthebo
Copy link
Contributor

summary: merged into master in f347bbe; this should be released in 1.3.0. Thanks again for the contribution!

Sharpie added a commit to Sharpie/hiera that referenced this pull request Feb 18, 2014
PR puppetlabs#152 broke a common use case:

    interpolate %{this} and %{this} again

Since each interpolation scans the entire input string and shares the same
recursion guard, this causes an InterpolationLoop error to be raised.
Sharpie added a commit to Sharpie/hiera that referenced this pull request Feb 18, 2014
PR puppetlabs#152 broke a common use case:

    interpolate %{this} and %{this} again

Since each interpolation scans the entire input string and shares the same
recursion guard, this causes an InterpolationLoop error to be raised.
Sharpie added a commit to Sharpie/hiera that referenced this pull request Feb 18, 2014
PR puppetlabs#152 broke a common use case:

    interpolate %{this} and %{this} again

Since each interpolation scans the entire input string and shares the same
recursion guard, this causes an InterpolationLoop error to be raised.
Sharpie added a commit to Sharpie/hiera that referenced this pull request Feb 18, 2014
PR puppetlabs#152 broke a common use case:

    interpolate %{this} and %{this} again

Since each interpolation scans the entire input string and shares the same
recursion guard, this causes an InterpolationLoop error to be raised.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants