So I've got a puppet manifest, with multiple resources

class foo {
  Custom::Resource {'resource1':
      attr1 => 'val1',
      attr2 => 'val2',
  Custom::Resource {'resource2':
      attr1 => 'val3',
      attr2 => 'val4',
  Custom::Resource {'resource3':
      attr1 => 'val5',
      attr2 => 'val6',

If I wanted to loop over the Custom::Resource resource names in an .erb template that are defined in class foo, how do I access them? So if I wanted to write out a template that looked like this:

ThisLine = resource1
ThisLine = resource2
ThisLine = resource3

1 Answer 1


Just in case you still want to know, I figured out how to iterate over resources inside puppet templates without any additional modules. Here's an example where I have a firewall module with a defined rule type (firewall::rule). I want to iterate over all instances of that type in a template, so I use:

<% scope.compiler.catalog.vertices.each do |resource| -%>
 <% if resource.type == "Firewall::Rule" -%> 
  # <%= resource[:comment] %>
 <% end -%> 
<% end -%>

That middle line "resource[:comment]" doesn't work right, I'm still trying to figure that part out. I asked about it on the puppet mailing list so we'll see if they get back to me. For reference, take a look at this post.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .