You've misunderstood what the indent parameter of |to_nice_yaml does|.
It doesn't shift everything to the right by that much. Rather, it tells
how much to indent those things which must be indented, like
dictionaries within dictionaries. You don't have any so it has no effect.
Use the |indent| filter instead.
|volumes: {{ volumes | to_nice_yaml() | indent(width=4, first=false) }} |
On 7/27/22 1:19 PM, jean-christophe manciot wrote:
The goal seems to be simple, but I cannot manage to get the
indentation right.
*Playbook*:
- name: Saving a list of dictionaries to a file
gather_facts: false
hosts:
- localhost
strategy: debug
tasks:
- name: Saving a list of dictionaries to a file
vars:
volumes:
- class: 'data'
id: 'a61b96e7-427e-493a-993c-c3efc8a16aa1'
size: '500GB'
type: 'ssd'
template:
src: "volumes.j2"
dest: "../files/volumes.yml"
*Template*:
volumes:
{{ volumes | to_nice_yaml(indent=10) }}
*Result*:
volumes:
- class: data
id: a61b96e7-427e-493a-993c-c3efc8a16aa1
size: 500GB
type: ssd
*Expected result*:
volumes:
- class: data
id: a61b96e7-427e-493a-993c-c3efc8a16aa1
size: 500GB
type: ssd
What is strange is that the indent value has no effect on the result.
Am I doing something wrong or is this an issue with ansible?
--
You received this message because you are subscribed to the Google
Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/9147b9cf-c1ab-4102-905c-7f720c4401c0n%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/9147b9cf-c1ab-4102-905c-7f720c4401c0n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Todd
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/ed0e313b-bd62-32d9-12fb-93be3473e832%40gmail.com.