Ansible – Template: to_nice_json

In order to create a file from the template and immediately save it as "Pretty JSON", you can use the "copy" module with the "content" key.

For example, save the template "config.j2" as the file "/app/config.json"

Playbook:

- name: Template a file to configuration files
  copy:
    content: "{{ lookup('template', 'templates/config.j2') | to_nice_json }}"
    dest: "/app/config.json"
    owner: artem
    group: artem
    mode: '0644'

Tagged: Tags

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments