Ask Your Question

Value from hiera nested hash in erb template

asked 2013-04-22 23:10:49 -0600

STOIE gravatar image

updated 2013-04-22 23:11:14 -0600

Hi there,

I have the following:

  someval: foovalue
  someval: barvalue

Now, I want to request the value of "foo::bar01::someval" and put it in a puppet erb template.


The first value is: <%= hiera(foo::bar01::someval) %>.

I just have no idea what the actual syntax is...

Can anyone help?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-04-23 00:49:56 -0600

jonn gravatar image

First, you need to perform the lookup from hiera:

$foo = hiera("foo")

You can then reference the relevant array/hash element within your template, using Ruby syntax:

<%= foo['bar01']['someval'] %>
edit flag offensive delete link more


Sweet as, that's what I need, so you have to do the lookup externally (in the manifest), then you just declare it like a nested hash in perl. - Hehe ...(more)

STOIE gravatar imageSTOIE ( 2013-04-23 01:38:43 -0600 )edit

Is there no way to invoke the hiera_hash function from within ruby itself? I don't want to avoid writing any puppet code - only templates and hiera files.

otheus gravatar imageotheus ( 2017-02-15 05:35:05 -0600 )edit

in puppet 3 you can use something like scope.function_hiera(["logging::fluentd_portmap", { 'default' => '24224' }] ) where logging::fluentd_portmap is your hiera yaml file path, and the second hash is a default value if the lookup fails. I do believe there are new ways to do this in puppet 4.

jayatlentecs gravatar imagejayatlentecs ( 2017-06-28 08:37:59 -0600 )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


Asked: 2013-04-22 23:10:49 -0600

Seen: 12,076 times

Last updated: Apr 23 '13