Cannot parse array into defined type

会有一股神秘感。 提交于 2019-12-11 10:46:37

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/25339461/cannot-parse-array-into-defined-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!