Ask Your Question
2

Hiera lookup function behaves differently in interpolation tokens

asked 2015-12-08 03:18:11 -0600

IRQ gravatar image

Dear Community,

I'm using Puppet 4.2.1 and I've recently discovered that the hiera() lookup function behaves differently for non-existent keys when used in a YAML interpolation token vs. when called directly. In the latter case, the following statements (correctly) raise an error:

CLI:
$ puppet apply -e "notice(hiera('non-existent'))"
Error: Evaluation Error: Error while evaluating a Function Call, Could not find data item non-existent in any Hiera data file and no default supplied...

site.pp:
class configuration {
  hiera('non-existent')
}
=> Same Error message

However, if I lookup a non-existent key in a YAML interpolation token, no error is being reported and the function seems to return the empty string:

YAML
---
limbo:    "%{hiera('non-existent)}"

I spent several hours debugging a puppet module, which failed due to a parameter set to the empty string. This unexpected behaviour was caused by the hiera() lookup function silently ignoring a key that wasn't initialised. Is this really intended behaviour? Or am I using the lookup function incorrectly? Have I missed something in the documentation?

Thank you for your help clarifying this issue

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-12-17 08:19:59 -0600

Nick H gravatar image

Unfortunately it seems to be the intended behaviour and is unavoidable. I've raised an issue in the Hiera project (since that's where the behaviour comes from) which hopefully will result in being able to have stricter interpolation in future.

https://tickets.puppetlabs.com/browse...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-08 03:13:46 -0600

Seen: 264 times

Last updated: Dec 08 '15