hiera_array() default value not taken

1,183 views
Skip to first unread message

Pablo Fernandez

unread,
Apr 2, 2012, 8:03:37 AM4/2/12
to puppet...@googlegroups.com
Hi,

There is probably something stupid I am missing, but I just can't see
it. I do:

$iptables_open_ports_public = hiera_array ('iptables_open_ports_public', [])

And I have not defined that in the hiera tree, so the default (an empty
array) should be returned. But I get, instead:

"Error 400 on SERVER: Could not find data item
iptables_open_ports_public in any Hiera data file and no default supplied"

Is there any special way to define an empty array as a parameter?

Thanks!
Pablo

Jason Koppe

unread,
Apr 6, 2012, 12:07:01 PM4/6/12
to Puppet Users
I have this problem too. Do defaults work for anyone?

Jason Koppe

unread,
Apr 6, 2012, 12:16:56 PM4/6/12
to Puppet Users
I'm using the YAML backend. Not sure if that's going to matter.

Hunter Haugen

unread,
Apr 6, 2012, 12:22:03 PM4/6/12
to puppet...@googlegroups.com
Looks like a default of [] triggers https://github.com/puppetlabs/hiera-puppet/blob/master/lib/puppet/parser/functions/hiera_array.rb#L32 to think that the `.lookup` function did not get an answer.

Hiera and Hiera-puppet have to distinguish between empty/false/nil answers sent by the backend due to missing data, or empty/false/nil answers explicitly returned as the default value or found value. Having hiera just return an empty answer when an answer is not found would probably not be preferable, so nil could possibly be the "not found" value?

-Hunter

psychobyte

unread,
Apr 6, 2012, 12:52:58 PM4/6/12
to puppet...@googlegroups.com
I don't think hiera likes defaults as array/hashes explicitly

I usually do a

$empty_hsh = {}
$empty_arr = []

and use those as default values.

HTH



On Monday, April 2, 2012 5:03:37 AM UTC-7, pablo.f...@cscs.ch wrote:

Jason Koppe

unread,
Oct 30, 2012, 2:25:43 PM10/30/12
to puppet...@googlegroups.com
we end up doing this a lot:

$var = hiera_hash('key','SOMESTRING')
if is_hash($var) { 
....
}

not the most elegant
Reply all
Reply to author
Forward
0 new messages