Ask Your Question

How do I access merged hiera data directly from a template?

asked 2014-10-09 14:33:14 -0600

CaptSpify gravatar image

I have hiera data that is being merged in via 3 different levels:

   - name/hostname
   - class/hostclass
   - global

and when I use a hiera_hash to extract the merged data in my module, it works fine:

$module_vars = hiera_hash('module_data', undef)

Unfortunately, I can't pass $module_vars directly to the template, because it's being called from a different module But, when I try to access the data directly from the erb template like so:

<% $module_vars = scope.function_hiera(['module_data']) -%>

I only get the first hiera set that it finds. I don't get the merged hiera data.

Is there a way I can make the template access the hiera data in the same way that hiera_hash does?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-10-09 15:18:02 -0600

llowder gravatar image

In the class that calls the template, do this:

require other_module::otherklass
$my_modules_vars = $other_module::otherklass::module_vars

and in the template, reference @my_module_vars.

You would need to use scope.function_hiera_hash() to cal it directly, but I would not recommend that as it will make it harder to maintain and to read.

edit flag offensive delete link more


I was hoping to avoid cross-contamination of my modules.

CaptSpify gravatar imageCaptSpify ( 2014-10-09 17:00:06 -0600 )edit

If you are using variables from another module, that is by definition, cross contamination.

llowder gravatar imagellowder ( 2014-10-10 07:17:34 -0600 )edit

haha, fair enough. I was hoping to avoid cross-contamination on the module level. The problem is: I need to get data from all of my other modules to *one* erb in my "base" module. I'd like to end up not loading all the vars from all of my other modules if I don't have to.

CaptSpify gravatar imageCaptSpify ( 2014-10-10 08:55:53 -0600 )edit

If these are classes, both classes can inherit defaults from another class whose only purpose is to get the default values from hiera.

robrwo gravatar imagerobrwo ( 2014-10-15 10:30:12 -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

1 follower


Asked: 2014-10-09 14:33:14 -0600

Seen: 1,305 times

Last updated: Oct 09 '14