How to refer to current iteration of hash loop in puppet

puppet

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

Best Answer

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}": }                                                
  }