Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
So I realised that this question which has the answer of using the puppet-concat module does indeed do what I was wanting. –  Dave Wongillies Mar 21 '12 at 11:44
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.