【发布时间】:2020-07-05 15:25:44
【问题描述】:
我想使用 Ansible 和模板模块填充配置文件。我将从另一个系统接收 json 有效负载,作为这种格式的一个衬里..
[
{
"customer": "customer_name",
"license_type": "eval",
"customFields": {
"test": 1234
}
},
{
"customer": "customer_name",
"license_type": "eval",
"customFields": {
"test": 123
}
}
]
压缩为单行:
[ { "customer": "customer_name", "license_type": "eval", "customFields": { "test": 1234 } }, { "customer": "customer_name", "license_type": "eval", "customFields": { "test": 123 } } ]
在我的 ansible 中,我将一个变量 (entire_lic) 设置为整个单行,然后在模板模块中我有一个名为 license.conf 的模板:
{{ entire_lic }}
这可行,但它不是很好地打印成可读的 json。无论如何我可以做到这一点吗?我试过了
{{ entire_lic | to_nice_json }}
但这似乎不起作用。任何帮助将不胜感激!
【问题讨论】:
-
查看调试模块并使用var属性。