Ask Your Question

Access hiera array element in erb template

asked 2016-06-29 20:10:05 -0600

cm01 gravatar image

updated 2016-06-29 21:12:57 -0600

So, I have

check_command                   check_nrpe!check_ntp_drift!<%= env['ntpservers'][0] %>

in a template .erb file.
This gives the error

 Function Call, Failed to parse template icinga/etc/icinga/COLLECT/icinga/base.cfg.erb:
  Filepath: /etc/puppetlabs/code/environments/prod/modules/icinga/templates/etc/icinga/COLLECT/icinga/base.cfg.erb
  Line: 50
  Detail: undefined local variable or method `env' for #<Puppet::Parser::TemplateWrapper:0x16f3ce66>

during a puppet agent run.
'env' is defined in site.pp

$env = hiera_hash(env)

Can anyone provide the correct syntax please (this is on puppet 4, ported from working puppet 3 if that helps)


@lupin: y, funnily enough I just tried that (randomly) and it worked.
My prob is I'm new to puppet and know zero about Ruby. I'm not clear on the different syntax's of each lang and eg whether/when to differentiate between hash, array, element of hash/array and what syntax to use in each case.

I guess this is 'Solved' :)

PS: If you're good with hiera, can you take a look at ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-29 20:45:37 -0600

lupin gravatar image

Is that a typo? Missing '@" in @env variable? Shouldn't read like:

check_nrpe!check_ntp_drift!<%= @env['ntpservers'][0] %>
edit flag offensive delete link more

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: 2016-06-29 20:10:05 -0600

Seen: 1,014 times

Last updated: Jun 29 '16