【问题标题】:Cannot parse array into defined type无法将数组解析为定义的类型
【发布时间】:2014-08-16 10:56:18
【问题描述】:

我正在使用以下木偶类

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

这是什么原因?

问候, 马林莎·阿迪卡里

【问题讨论】:

    标签: puppet puppetlabs-apache


    【解决方案1】:

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

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

    【讨论】:

    • 这给了我一个错误错误:无法从远程服务器检索目录:服务器上的错误 400:在节点上找不到定义映射
    • 我在stackoverflow.com/questions/25351350/… 中用我的真实场景提出了这个问题。请注意这一点
    • 如果这个答案对您有所帮助,请考虑投票并接受它。
    猜你喜欢
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 2017-11-07
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多