2

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
Dave Wongillies
  • 462
  • 4
  • 8
  • So I realised that [this question](http://serverfault.com/questions/366088/iterate-resources-in-a-puppet-template) which has the answer of using the [puppet-concat module](https://github.com/ripienaar/puppet-concat) does indeed do what I was wanting. – Dave Wongillies Mar 21 '12 at 11:44

1 Answers1

2

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.

ctrlc-root
  • 181
  • 1
  • 8