在 Puppet 中解析 JSON 字符串

Parse a JSON string in Puppet

我正在尝试解析 Puppet 清单中的一个非常简单的 json 文件,但正在努力解决它。

以下示例 Puppet 清单有效,但它仅打印 json 文件中的条目

include stdlib
$hash = loadjson('/tmp/file.json')
notify("$hash")

JSON 文件

{
  "output": {
    "message": "This is the entire value",
    "return_value": "0"
  }
}

我希望能够将 "message" 分配给变量“$message”,将 "return_value" 分配给变量“$return_value”

你会写:

  $hash = loadjson('/tmp/file.json')
  $message      = $hash['output']['message']
  $return_value = $hash['output']['return_value']
  notice("$message, $return_value")

或者更简洁:

  $hash = loadjson('/tmp/file.json')
  [$message, $return_value] = $hash['output']
  notice("$message, $return_value")

正如上面评论中提到的,这里没有实际需要include stdlib