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.

I have a hash like so

net:ip { '':
ip => {
    ip1 => {
       addr => '192.168.10.1',
       device => 'eth0',
    },
    ip2 => {
      addr => '192.168.50.10',
      device => 'eth10',
    },
}
}

In my manifest I call like so

define net::ip (
$ip={},
) {
  ...
}

my question is how do I refer to the current loop of the hash iteration. I want to be able to use the "dev" field in this manifest, but since the hash has ip1,ip2 I can't tell what number its on?

Thanks Dan

share|improve this question
    
You're passing that hash to the defined type, but you're not showing us what's happening in that defined type; you'll need to clarify how exactly you're 'looping' over the hash - is it within an erb template? –  Shane Madden Mar 13 '13 at 5:00
    
Apologies, thought that part wasn't relevant. Currently I am iterating over the loop in my erb template. But I need to access the device for each hash element inside the manifest. So really that's where my problem is. I understand that we can't do loops in manifests, but is there a way to get the device from a call? Thanks Dan –  Dan Mar 13 '13 at 10:37
add comment

1 Answer 1

Following example may help. Create the hash separately and access it through a define type.

  $foo = [{"addr" => "bar", "port" => "1"},                                     
          {"addr" => "bat", "port" => "2"}]                                     
  testmod::bar {$foo:}                                                          
  define testmod::bar () {                                                      
    $var1 = $name["addr"]                                                       
    $var2 = $name["port"]                                                       
    notify {"${var1}_${var2}": }                                                
  }      
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.