Bug #15857

Difference between not set, empty and empty default

Added by Daniele Sluijters 11 months ago. Updated 4 months ago.

Status:ClosedStart date:08/06/2012
Priority:NormalDue date:
Assignee:Daniele Sluijters% Done:

0%

Category:hiera
Target version:-
Keywords: Affected Hiera Version:
Branch:

Description

Hiera has apparently been designed to not differentiate between a variable it cannot find because it is not defined anywhere, an empty variable or an empty default passed in the module.

This is surprisingly frustrating at times where an empty hash/string makes sense as a default but Hiera/Puppet will always furiously complain that the variable you’re trying to use was not found/defined. This results in needing to do stuff like this:

$var = hiera(‘some_var’, ‘default’)

if $var == ‘default’ $var_real = {} else $var_real = $var

And then use $var_real in the rest of the module.

Honestly, this is ugly and shouldn’t be necessary, there’s a subtle yet significant difference between a variable not being declared anywhere, being declared as an empty hash/array/string or being passed in through an (empty) module default.

History

#1 Updated by eric sorenson 10 months ago

Hi Daniele, thank you for the ticket — what version of puppet was this running against? I wonder if the fixes in the 3.0 series will fix this as a side effect, as this problem is really puppet and not hiera. See #15329 for the back-story.

#2 Updated by eric sorenson 10 months ago

  • Status changed from Unreviewed to Needs More Information
  • Assignee set to Daniele Sluijters

#3 Updated by Andrew Parker 4 months ago

  • Status changed from Needs More Information to Closed

This does not appear to be a problem anymore

[08:10:05][Ruby(ruby-1.9.3-p125)] andy:manifests
> puppet apply -e 'notice(hiera("does_not_exist", false))'
Notice: Scope(Class[main]): false
Notice: Finished catalog run in 0.22 seconds
[08:10:32][Ruby(ruby-1.9.3-p125)] andy:manifests
> puppet apply -e 'notice(hiera("does_not_exist", {}))'
Notice: Scope(Class[main]): {}
Notice: Finished catalog run in 0.22 seconds
[08:10:39][Ruby(ruby-1.9.3-p125)] andy:manifests
> puppet apply -e 'notice(hiera("does_not_exist", []))'
Notice: Scope(Class[main]): 
Notice: Finished catalog run in 0.21 seconds
[08:10:46][Ruby(ruby-1.9.3-p125)] andy:manifests
> puppet apply -e 'notice(hiera("does_not_exist", ""))'
Notice: Scope(Class[main]): 
Notice: Finished catalog run in 0.22 seconds

This is with:

[08:10:53][Ruby(ruby-1.9.3-p125)] andy:manifests
> puppet --version
3.1.0
[08:11:18][Ruby(ruby-1.9.3-p125)] andy:manifests
> hiera --version
1.1.2

Technically I’m running from the master branch from the repo, but the version number should be close to what this is.

If this is still an issue, please provide information on how to reproduce it and re-open this bug.

Also available in: Atom PDF