Ask Your Question
2

Hiera and templates

asked 2013-09-25 06:09:13 -0500

shyp gravatar image

updated 2013-09-25 11:47:29 -0500

ramindk gravatar image

Hi , I know I am able to work with Hiera and templates with class in the middle ...

manifests/init.pp

class foo ( 
    $ip = hiera('jrs_config_server1', ''), 
) { 
}

templates/some_template.erb

<% ip = scope.lookupvar('foo::ip') -%>

Is there a way to call to hiera , directly from the template ?

edit retag flag offensive close merge delete

Comments

Which puppet version are you using? You should be able to access the variable inside a template in the module "foo" with just <%= @foo %> This is fairly short.

andreas gravatar imageandreas ( 2013-09-25 09:04:38 -0500 )edit

Hi , They are not on the same manifests the code you see . the class is out of scope . but the q is , is there a way to call to hiera ...(more)

shyp gravatar imageshyp ( 2013-09-25 10:24:58 -0500 )edit
spuder gravatar imagespuder ( 2014-08-28 16:48:47 -0500 )edit

This method is a really clever and sensible way to avoid puppet coding, while focusing on configuration layouts and parameters. The documentations' discouragements are baffling. Ramindk's answer was correct. If the hiera value is a hash or array, these are treated natively by the ruby code.

otheus gravatar imageotheus ( 2017-02-16 22:01:38 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-09-25 11:45:34 -0500

ramindk gravatar image

It's just a matter of calling the Hiera function

# populate a var in your Ruby code
<% options = scope.function_hiera(['common::mon_ips']) -%>

# fill in a value
<%= scope.function_hiera(['database::master']) %>
edit flag offensive delete link more

Comments

Not working for me[version 2016.2]. Filepath: /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/functions/fail.rb Line: 3 Detail: hiera() has been converted to 4x API-- I tried 2 diff Lookup function: -scope().call_function('hiera', ['var1']) -scope.function_hiera(['var2']) Any idea?

rajeevsharma gravatar imagerajeevsharma ( 2016-07-08 07:05:03 -0500 )edit

Instead you can try this (supports for puppet >= 4.x.x ) <%= scope().call_function('hiera',['database::master']) %>

abhijit940 gravatar imageabhijit940 ( 2016-10-06 05:20:27 -0500 )edit

Yet another reason I hate puppet/hiera dev team: they make pointless silly changes like this one.

otheus gravatar imageotheus ( 2017-02-16 22:02:24 -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

2 followers

Stats

Asked: 2013-09-25 06:09:13 -0500

Seen: 11,501 times

Last updated: Sep 25 '13