Vlad
2012-Feb-10 03:49 UTC
[Puppet Users] Hiera data unusable in a class with an array parameter
Given the following hiera hash: common.yaml: --- *allowed_ips:* * "First IP": 1.2.3.4* * "Second IP": 5.6.7.8* and the module: *class iptables ($role) {* * file {/tmp/test:* * content => template(iptables/test.erb)* * }* *}* with the corresponding template test.erb: *<% role.each do |role| -%> * * code* *<% end %>* *<% scope.function_hiera(''allowed_ips'').each do |comment, ip| -%> * * code <%= ip %> code # <%= comment %>* *<% end %>* And finally calling them in the node: *node example.com {* * class {"iptables":* * role => ["role1", "role 2"]* * }* *}* The above configuration gives the following error:> Error 400 on SERVER: Failed to parse template iptables/test.erb: can''t > convert Array into String at .../iptables/manifests/init.pp:3 on node > example.comThe weird part is that taken individually (either using only the role array or only the hiera hash) they work perfectly. But when I combine them in the same template I get the above error. And it doesn''t have to be necessarily a hiera hash or inside a template. Any hiera data called from a class with an array p*arameter. * Am I doing something wrong? It might be a bug but I want to first make sure that I am using this the right way. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/AKM_WbSvMAsJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nan Liu
2012-Feb-10 03:52 UTC
Re: [Puppet Users] Hiera data unusable in a class with an array parameter
What you want is the hiera_array instead of hiera function. There''s also a hiera_hash function. Thanks Nan On Feb 9, 2012, at 19:49, Vlad <vlad@vladgh.com> wrote: Given the following hiera hash: common.yaml: --- *allowed_ips:* * "First IP": 1.2.3.4* * "Second IP": 5.6.7.8* and the module: *class iptables ($role) {* * file {/tmp/test:* * content => template(iptables/test.erb)* * }* *}* with the corresponding template test.erb: *<% role.each do |role| -%> * * code* *<% end %>* *<% scope.function_hiera(''allowed_ips'').each do |comment, ip| -%> * * code <%= ip %> code # <%= comment %>* *<% end %>* And finally calling them in the node: *node example.com {* * class {"iptables":* * role => ["role1", "role 2"]* * }* *}* The above configuration gives the following error:> Error 400 on SERVER: Failed to parse template iptables/test.erb: can''t > convert Array into String at .../iptables/manifests/init.pp:3 on node > example.comThe weird part is that taken individually (either using only the role array or only the hiera hash) they work perfectly. But when I combine them in the same template I get the above error. And it doesn''t have to be necessarily a hiera hash or inside a template. Any hiera data called from a class with an array p*arameter. * Am I doing something wrong? It might be a bug but I want to first make sure that I am using this the right way. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/AKM_WbSvMAsJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Vlad
2012-Feb-10 04:47 UTC
Re: [Puppet Users] Hiera data unusable in a class with an array parameter
Thanks Nan, I''ve tried them all (hiera, hiera_array and hiera_hash), unfortunately with no luck. Like I mentioned above, it doesn''t have to be necessarily a hiera hash. Even a simple var: name inside the yaml file gives that error. As long as you have an array defined as a parameter, together with any type of variable from hiera (string, array, or hash), it doesn''t work. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/U6a7O_EwdyYJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Gary Larizza
2012-Feb-10 04:51 UTC
Re: [Puppet Users] Hiera data unusable in a class with an array parameter
Vlad, Have you tried setting the variable inside your Puppet manifest before you call it in the template? Something like: $ips = hiera_hash(''allowed_ips'') file {/tmp/test: content => template(iptables/test.erb) } And then in the template: *<% ips.each do |comment, ip| -%> * * code <%= ip %> code # <%= comment %>* *<% end %>* I''ve not seen too many people calling hiera inside a function - let''s eliminate this first and see what happens. On Thu, Feb 9, 2012 at 8:47 PM, Vlad <vlad@vladgh.com> wrote:> Thanks Nan, I''ve tried them all (hiera, hiera_array and hiera_hash), > unfortunately with no luck. > Like I mentioned above, it doesn''t have to be necessarily a hiera hash. > Even a simple var: name inside the yaml file gives that error. As long as > you have an array defined as a parameter, together with any type of > variable from hiera (string, array, or hash), it doesn''t work. > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/U6a7O_EwdyYJ. > > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- Gary Larizza Professional Services Engineer Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Gabriel Filion
2012-Feb-10 04:53 UTC
Re: [Puppet Users] Hiera data unusable in a class with an array parameter
try adding this in your template above the call to scope.function_hiera_array(): <% Puppet::Parser::Functions.function(''hiera_array'') -%> On 12-02-09 11:47 PM, Vlad wrote:> Thanks Nan, I''ve tried them all (hiera, hiera_array and hiera_hash), > unfortunately with no luck. > Like I mentioned above, it doesn''t have to be necessarily a hiera hash. > Even a simple var: name inside the yaml file gives that error. As long > as you have an array defined as a parameter, together with any type of > variable from hiera (string, array, or hash), it doesn''t work. > > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/U6a7O_EwdyYJ. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en.-- Gabriel Filion -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Vlad
2012-Feb-10 05:09 UTC
Re: [Puppet Users] Hiera data unusable in a class with an array parameter
Thanks Gary and Lelutin. Gary: That was the first thing I tried, and no luck there either. I even took out the template out of the equation and called a simple variable like: common.yaml:> *--- > **test: testvar*> *class test ($role) {**$ips = hiera(''test'')> **notify {"${ips}:}*} No success here either. If I get rid of the $role parameter, it simply works. If I get rid of the hiera lookup, and keep only the role (notify {"${role}":}), it works. But not together. Lelutin: I just tested your suggestion but it still doesn''t work. I forgot to mention that I have hiera and hiera-puppet gems (0.3.0) plus a checkout of hiera-puppet inside my modules folder. And yes all functions are pluginsynced across all agents. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/CyfwbFo1lMYJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nan Liu
2012-Feb-10 05:57 UTC
Re: [Puppet Users] Hiera data unusable in a class with an array parameter
On Thu, Feb 9, 2012 at 9:09 PM, Vlad <vlad@vladgh.com> wrote:> Thanks Gary and Lelutin. > > Gary: That was the first thing I tried, and no luck there either. I even > took out the template out of the equation and called a simple variable like: > common.yaml: >> >> --- >> test: testvar > > >> >> class test ($role) { >> >> $ips = hiera(''test'') >> notify {"${ips}:} >> >> } > > No success here either. If I get rid of the $role parameter, it simply > works. If I get rid of the hiera lookup, and keep only the role (notify > {"${role}":}), it works. But not together. > > Lelutin: I just tested your suggestion but it still doesn''t work. I forgot > to mention that I have hiera and hiera-puppet gems (0.3.0) plus a checkout > of hiera-puppet inside my modules folder. And yes all functions are > pluginsynced across all agents.What does your heira.yaml configuration file look like? are you using %{role} in hiera.yaml hierarchy by any chance? Thanks, Nan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Vlad
2012-Feb-10 06:23 UTC
Re: [Puppet Users] Hiera data unusable in a class with an array parameter
That fixes it! Thanks. In all my debugging I assumed that " can''t convert Array into String " referred to the hiera variables. And it was about the role variable all along. You were right, I had a top scope variable role defined in a custom fact, which was also in the hiera hierarchy, and another role passed as a parameter to the module. Now I wonder why without hiera they can both live together. Probably the hiera call that resides inside the module gets the local scope for hierarchy and not the global one, so it creates each hierarchical string with an array passed from the parameter. Anyway, thanks for your prompt answer. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/1RKe1u4HztkJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.