ali*_*227 2 json jinja2 ansible
我正在尝试使用 jinja2 模板编写一个配置文件并将文件保存为 .json 并对其进行漂亮的格式化。
如何将输出文件保存为变量,然后使用 to_nice_json 将其格式化为 JSON?这个剧本是从另一个主要剧本中调用的角色的一部分。目前,它将配置文件写入 Windows 主机,但未格式化为 JSON。
---
#Write config file
- name: Deploy configuration file
template: src=templates/config.j2 dest="C:\\SomeDir\\
{{web_app.name}}_config.json"
Run Code Online (Sandbox Code Playgroud)
尝试模板查找:
- name: Deploy configuration file
win_copy:
content: "{{ lookup('template', 'templates/config.j2') | to_nice_json }}"
dest: "C:\\SomeDir\\{{web_app.name}}_config.json"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10978 次 |
| 最近记录: |