Ask Your Question
1

Value from hiera nested hash in erb template

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

STOIE gravatar image

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

Hi there,

I have the following:

---
foo:
 bar01:
  someval: foovalue
 bar02:
  someval: barvalue

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

eg.

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

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

Can anyone help?

Aaron.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

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

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

Comments

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 -0500 )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 -0500 )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 -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

Stats

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

Seen: 9,587 times

Last updated: Apr 23 '13