无法将数组解析为已定义的类型

时间:2014-08-16 10:56:18

标签: puppet puppetlabs-apache

我正在使用以下木偶类

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

这是什么原因?

此致 Malintha Adikari

1 个答案:

答案 0 :(得分:2)

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

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

 map {$foo:}

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

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

  1. 构建数据的哈希,而不是哈希数组
  2. 使用create_resources函数
  3. 未经测试的示例代码:

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