1

我正在使用以下木偶类

class myclass{

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

      map {$foo:}

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

}

但这给了我

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

这是什么原因?

问候, 马林莎·阿迪卡里

4

1 回答 1

2

您的数组包含哈希。资源声明语法仅适用于字符串数组。

 $foo = ["bar", "baz"]

 map {$foo:}

 define map () { notify {$name: } }

如果要传递每个资源标题的数据,则需要

  1. 构建数据的散列,而不是散列数组
  2. 使用create_resources功能

未经测试的示例代码:

$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": } } 
于 2014-08-16T15:09:25.930 回答