如何在ansible中使用模板编写漂亮的JSON文件?

3
我正在尝试使用jinja2模板编写配置文件并将文件保存为.json格式,并进行美化格式。
如何将输出文件保存为变量,然后使用to_nice_json格式化为JSON?这个角色是从另一个主要的playbook中调用的一部分。目前,它将配置文件写入Windows主机,但未格式化为JSON。
---
#Write config file
- name: Deploy configuration file
  template: src=templates/config.j2 dest="C:\\SomeDir\\
{{web_app.name}}_config.json"
1个回答

7
尝试模板查找:
- name: Deploy configuration file
  win_copy:
    content: "{{ lookup('template', 'templates/config.j2') | to_nice_json }}"
    dest: "C:\\SomeDir\\{{web_app.name}}_config.json"

是的,那个有效,谢谢。输出文件是格式化后的 JSON。 - alig227

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接