Ask Your Question
0

How to access map variable using hiera?

asked 2015-12-15 21:56:33 -0500

VeekshaVasanth gravatar image

updated 2015-12-16 00:23:07 -0500

# test.yaml
x-certificate:
 id:'xxxxx'
 name:'x'

How to access id value of x-certificate using hiera? Is it possible?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-12-16 00:29:36 -0500

From your code you'd have something like:

$xcert = hiera('x-certificate')
$id = $xcert['id']

Note that in general it is considered best practice to use the automatic parameter lookup feature of parameterised classes for reading in the data from hiera, rather than making explicit calls to hiera using the hiera function, as I have shown here.

edit flag offensive delete link more

Comments

Is "automatic parameter lookup" really considered best practice? I was reading the "Data Bindings" sections of Gary Larizza's blog here: http://garylarizza.com/blog/2014/10/24/puppet-workflows-4-using-hiera-in-anger/ where he raised some concerns about readability and performance.

Simon gravatar imageSimon ( 2015-12-17 04:35:51 -0500 )edit

I don't personally agree with what Gary says there, but I can't tell you whether there's a consensus or not in the community on this point. To make up your own mind, I would browse puppet labs supported modules and see what they do.

Alex Harvey gravatar imageAlex Harvey ( 2015-12-17 07:44:19 -0500 )edit

The counterargument to "seems like magic" ie action-at-a-distance would be that to not use this feature results inevitably in redundant code and noise. I think conciseness, plus an assumption that programmers must accept some features of a language, trumps the concern about magic.

Alex Harvey gravatar imageAlex Harvey ( 2015-12-17 07:49:49 -0500 )edit

If you know perl at all, many have complained - especially newcomers to the language - that use of $_ is far too much like magic. And maybe it is, but it's definitely a feature you should use, anyway, because it's idiomatic for perl. I think it's the same here.

Alex Harvey gravatar imageAlex Harvey ( 2015-12-17 07:51:34 -0500 )edit

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-15 21:56:33 -0500

Seen: 153 times

Last updated: Dec 16 '15