Puppet, hiera and erb – erb would not recognize array

hierapuppettemplate

I have a pretty annoying error I am desperate to fix. I have a puppet module where certain things are kept in a yaml file (hiera) so that people could quickly edit just that part.

The structure is nested.

The template like this:

<%= @platforms[@platform]['users_allowed'][@host].class %>

renders to this:

Array

But when I try to iterate over it:

<% @platforms[@platform]['users_allowed'][@host].each do | pubkey | %>
<%= pubkey %>
<% end %>

puppet says:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template somemodule/templates/authorized_keys.erb:
Filepath: /etc/puppet/modules/somemodule/templates/authorized_keys.erb
Line: 1
Detail: undefined method `each' for nil:NilClass

How does it suddenly become nil and how do I iterate here?

I'm afraid I'm stuck here and not even sure in which direction I should search for solution.

Rewriting module without hiera or without nested structure is not an option in this one case.

Best Answer

I've tested on my puppet and the correct syntax that worked was:

<% @platforms[@platform]['users_allowed'][@host].each do | pubkey | -%>
  <%= pubkey %>
<% end -%>

I hope I helped.