无法将数组解析为定义的类型 [英] Cannot parse array into defined type

查看:81
本文介绍了无法将数组解析为定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下木偶课程

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']: } }

}

但这给了我

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

这是什么原因?

问候,玛琳莎·阿迪卡里

Regards, Malintha Adikari

推荐答案

您的数组包含散列.资源声明语法仅适用于字符串数组.

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. 构建数据的散列,而不是散列数组
  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": } } 

这篇关于无法将数组解析为定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆