I have a hash, built from yaml via stdlib, which includes arrays within the hash. Here is a sample of the yaml:
datacenter1:
propertyA:
- associatedItem
cage1:
serviceA:
- server1
- server2
serviceB:
- server10
backupCage:
cage2
cage2:
serviceA:
- server3
- server4
- server5
serviceB:
- server11
backupCage:
cage1
datacenter2:
cage1:
serviceA:
- server20
- server21
datacenter3:
propertyZ:
serviceD:
- server200
- server201
in this case I need to get a list of servers which offer a service within a particular datacenter in erb. Ultimately this is just going to need to output in text with some arbitrary data added for an conf file. I'm trying to get all servers providing serviceA for a given datacenter, in this example for datacenter1:
thiscommand blahblah server1
thiscommand blahblah server2
thiscommand blahblah server3
thiscommand blahblah server4
thiscommand blahblah server5
I use this map extensively for a variety of things, but this is the first case in which i can't just set a variable in puppet and iterate over that as a single array in erb.
EDIT1: This data comes from puppet but i am trying to use it in erb via template().
EDIT2: Note this code would never run against datacenter3, since this code is specific to datacenters which run serviceA.
Edit3: This is the form that ended up working: <% @hash['datacenter1'].values.each do |v| %>
<%- if v.is_a?(Hash) and v.has_key?('serviceA') -%>
<% v['serviceA'].each do |myservice| %>
thiscommand blah blah <%= myservice -%>
<% end %>
<% end %>