将哈希作为json在puppet epp模板中写
我面对从木偶中的.epp模板打印值时
- ,我在hiera中有以下数据,该数据定义了组(hashes的数组)
profiles::groups:
- name: 'admins'
type: 1
rights: []
- name: 'users'
type: 2
rights: []
- 上面的hiera键在.epp模板中称为上述
.....
groups = <%= require 'json'; JSON.pretty_generate scope['groups'] %>
.....
- 声明中的。 (从上方的EPP模板),但
.......
groups = [
{
"name": "admins",
"type": 1,
"rights": []
},
{
"name": "users",
"type": 2,
"rights": []
}
]
.....
Error Message: Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, epp(): Invalid EPP: Syntax error at 'json'
在.erb模板中声明相同格式的同时,给出了错误,并产生所需的输出。
I am facing while printing values from .epp template in puppet
- I have following data in hiera, which defines groups (array of hashes)
profiles::groups:
- name: 'admins'
type: 1
rights: []
- name: 'users'
type: 2
rights: []
- The above hiera key is called in .epp template like this
.....
groups = <%= require 'json'; JSON.pretty_generate scope['groups'] %>
.....
- Above declaration should print the values in file in following format (from above epp template) but gives error as mentioned below
.......
groups = [
{
"name": "admins",
"type": 1,
"rights": []
},
{
"name": "users",
"type": 2,
"rights": []
}
]
.....
Error Message: Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, epp(): Invalid EPP: Syntax error at 'json'
While declaring the same format in .erb template works fine and it produces desired output.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在ERB中,它是嵌入式Ruby,您可以使用常规红宝石功能,在EPP上是嵌入式木偶,因此您需要使用木偶功能。 There is a to_json_pretty available in stdlib https://forge.puppet.com/modules/puppetlabs/stdlib 将完成这项工作,您可以这样使用;
我刚刚对其进行了测试;
In erb it's embedded ruby you can use regular ruby functions, on epp it's embedded Puppet so you need to use Puppet functions. There is a to_json_pretty available in stdlib https://forge.puppet.com/modules/puppetlabs/stdlib which will do the job and you can use it like this;
I've just tested it out with;