Bernd Adamowicz
2010-Apr-30 07:42 UTC
[Puppet Users] Some advice on using hashes in ERB templates needed
Hi all, I''m working with Puppet version 0.25.4 and as far as I have read in this list it''s not possible to access complex data structures from within an ERB template, instead serializing is needed. Due to my lack of Ruby knowledge I didn''t find the right solution for this problem: Given this Yaml (coming out of an external node definition): --- classes: - vim - users - templates_eval::testvars environment: test parameters: workers: bo-01-010101: type: ajp13 host: myhostname.net Now I want to iterate over the ''workers'' inside the ERB template and tried (among others) this: 16 <% workers.each do |worker| -%> 17 <%= @m_worker = Marshal.load(worker) %> 18 worker.<%= worker %>.type=<%= @m_worker.type %> ... 25 26 <% end -%> Accessing the ''workers'' hash works, but accessing ''worker.type'' and ''worker.host'' not. I guess I will have to learn Ruby now ;-) but in the meantime, can some Ruby expert please tell me how to do this? Thanks a lot in advance! Bernd -- 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.
Michael DeHaan
2010-Apr-30 13:18 UTC
Re: [Puppet Users] Some advice on using hashes in ERB templates needed
> > Now I want to iterate over the ''workers'' inside the ERB template and tried (among others) this: > > 16 <% workers.each do |worker| -%> > 17 <%= @m_worker = Marshal.load(worker) %> > 18 worker.<%= worker %>.type=<%= @m_worker.type %> > ... > 25 > 26 <% end -%> > > Accessing the ''workers'' hash works, but accessing ''worker.type'' and ''worker.host'' not. I guess I will have to learn Ruby now ;-) but in the meantime, can some Ruby expert please tell me how to do this? Thanks a lot in advance! > > Bernd >worker[''type''] and worker[''host''] is the way the Ruby should look. --Michael -- 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.
Michael DeHaan
2010-Apr-30 13:19 UTC
Re: [Puppet Users] Some advice on using hashes in ERB templates needed
On Fri, Apr 30, 2010 at 9:18 AM, Michael DeHaan <michael@puppetlabs.com> wrote:>> >> Now I want to iterate over the ''workers'' inside the ERB template and tried (among others) this: >> >> 16 <% workers.each do |worker| -%> >> 17 <%= @m_worker = Marshal.load(worker) %> >> 18 worker.<%= worker %>.type=<%= @m_worker.type %> >> ... >> 25 >> 26 <% end -%> >> >> Accessing the ''workers'' hash works, but accessing ''worker.type'' and ''worker.host'' not. I guess I will have to learn Ruby now ;-) but in the meantime, can some Ruby expert please tell me how to do this? Thanks a lot in advance! >> >> Bernd >> > > worker[''type''] and worker[''host''] is the way the Ruby should look. >Also, you shouldn''t need Marshal.load and the @m_worker either. -- 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.
Bernd Adamowicz
2010-May-03 12:50 UTC
AW: [Puppet Users] Some advice on using hashes in ERB templates needed
Following your advice, the server reports this error: err: Failed to parse template templates_eval/worker.properties.erb: (eval):17:in `[]''cannot convert String into Integer at /etc/puppet/modules/templates_eval/manifests/init.pp:68 on node mynode.net This is the code I''ve used: 16 <% workers.each do |worker| -%> 17 worker.<%= worker %>.type=<%= worker[''type''] %> 18 worker.<%= worker %>.host=<%= worker[''host''] %> ... 24 25 <% end -%> I''ve already tried this before and as far as I''ve read in some other posts here, this is still not supported by Puppet in the current version. Only some kind of marshalling workaround might be possible. But I don''t know how to accomplish marshalling inside an ERB template. Any ideas? Bernd> -----Ursprüngliche Nachricht----- > Von: puppet-users@googlegroups.com [mailto:puppet- > users@googlegroups.com] Im Auftrag von Michael DeHaan > Gesendet: Freitag, 30. April 2010 15:20 > An: puppet-users@googlegroups.com > Betreff: Re: [Puppet Users] Some advice on using hashes in ERB > templates needed > > On Fri, Apr 30, 2010 at 9:18 AM, Michael DeHaan > <michael@puppetlabs.com> wrote: > >> > >> Now I want to iterate over the ''workers'' inside the ERB template and > tried (among others) this: > >> > >> 16 <% workers.each do |worker| -%> > >> 17 <%= @m_worker = Marshal.load(worker) %> > >> 18 worker.<%= worker %>.type=<%= @m_worker.type %> > >> ... > >> 25 > >> 26 <% end -%> > >> > >> Accessing the ''workers'' hash works, but accessing ''worker.type'' and > ''worker.host'' not. I guess I will have to learn Ruby now ;-) but in the > meantime, can some Ruby expert please tell me how to do this? Thanks a > lot in advance! > >> > >> Bernd > >> > > > > worker[''type''] and worker[''host''] is the way the Ruby should look. > > > > Also, you shouldn''t need Marshal.load and the @m_worker either. >-- 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.