On Saturday, August 16, 2014 2:22:40 AM UTC-5, Malintha Adikari wrote: > > Hi, > > 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 > catalogerr: Could not retrieve catalog; skipping run* > What is the reason for this ? > >
The reason is that your code is broken. Resource names / titles are *strings*. If you try to use a hash as a resource title (via a variable, since a hash literal in that position won't even parse) then it is stringified for use as the name. The "ip1.1.1.1idbar" resource title is exactly such a stringified hash. If you want to feed a hash to your defined type then do it via a parameter. With respect to the details of your code, it looks like you might be searching for the create_resources() <https://docs.puppetlabs.com/references/3.4.stable/function.html#createresources> function. Your data take a form similar (but not identical) to the one consumed by create_resources. In addition, I strongly recommend choosing a different name than "map" for your defined type, as "map" is the name of a built-in function in the future parser. In fact, the defined type's name in your example is really "myclass::map", which is basically ok as long as you refer to it by that name, but that would be much clearer if you did not nest the type definition inside your class. It is poor style to nest class or type definitions inside (other) classes; instead, each should reside in its own file. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/4824d378-d36a-4979-a3a6-77dd2ed6911e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.