1

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

Malintha
  • 4,512
  • 9
  • 48
  • 82

1 Answers1

2

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": } } 
Felix Frank
  • 8,125
  • 1
  • 23
  • 30
  • this gives me an error err: Could not retrieve catalog from remote server: Error 400 on SERVER: Cannot find definition Map on node – Malintha Aug 17 '14 at 16:22
  • I asked the question with my real scenario in http://stackoverflow.com/questions/25351350/cannot-create-files-inside-defined-type. Please look in to that kindly – Malintha Aug 17 '14 at 16:46
  • If this answer has helped you, please consider voting and accepting it. – Felix Frank Aug 17 '14 at 17:19