我正在通过使用 to_json
过滤器将一些 YAML 转换为 json 来创建一个 JSON 文件,例如如下
- name: Create JSON file
copy:
content: "{{ some_ansible_dict_var|to_json(ensure_ascii=False) }}"
dest: /tmp/content.json
to_json
过滤器似乎总是在一行中创建 json 内容。有没有办法用缩进等将内容格式化为多行?
答案 0 :(得分:1)
您可以使用 to_nice_json
过滤器。它记录在here。
您也可以指定缩进:{{ some_ansible_dict_var | to_nice_json(indent=2) }}