I have a hash like so

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

In my manifest I call like so

define net::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

  • 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? Mar 13, 2013 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, 2013 at 10:37

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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