Puppet, hiera and erb - erb would not recognize array
6,399
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.
Related videos on Youtube
Author by
Roman Grazhdan
Updated on September 18, 2022Comments
-
Roman Grazhdan over 1 year
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.
-
Zypher about 10 yearswhat version of puppet?
-
Roman Grazhdan about 10 yearsIt's 3.3.1. I belive the part of the problem is this (quoting puppetlabs docs): The lookup functions and the automatic parameter lookup always return the values of top-level keys in your Hiera data — they cannot descend into deeply nested data structures and return only a portion of them. To do this, you need to first store the whole structure as a variable, then index into the structure from your Puppet code or template. -- but it's still weird to me. It does see the type and it can render a template with the whole array but it can't index.
-
-
Roman Grazhdan about 10 yearsWhat version of puppet do you run? I think omitting one pipe must not help and if it does I'm in trouble. I mean, in Ruby array.each do | i | is valid, so it should be valid in erb, too.
-
PoLIVoX about 10 yearsWhen I typed I forgot to type a |. I already fix. Sorry for the mistake. Answering your question: Puppet 3.4.3. I used as the documentation recommends: docs.puppetlabs.com/learning/templates.html