puppetpuppetlabs-apache

Cannot parse array into defined type


I am using following puppet class

class myclass{

      $foo = [{"id" => "bar", "ip" => "1.1.1.1"}, {"id" => "baz", "ip" => "2.2.2.2"}]

      map {$foo:}

     define map () { notify {$name['id']: } }

}

But this gives me

err: Could not retrieve catalog from remote server: Could not intern from pson: Could not convert from pson: Could not find relationship target "Change_config::Map[ip1.1.1.1idbar]"
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run

What is the reason for this ?

Regards, Malintha Adikari


Solution

  • Your array contains hashes. The resource declaration syntax works only for arrays of strings.

     $foo = ["bar", "baz"]
    
     map {$foo:}
    
     define map () { notify {$name: } }
    

    If you want to pass data with each resource title, you need to

    1. build a hash of your data, not an array of hashes
    2. use the create_resources function

    Untested example code:

    $foo = { 
      "bar" => { "ip" => "1.1.1.1" }, 
      "baz" => { "ip" => "2.2.2.2" },
    }
    
    create_resources('map', $foo)
    
    define map ($ip="") { notify { "$name has ip $ip": } }