I have the variable CONNECTION_DATA in the vars group inside an ansible playbook:
vars:
CONNECTION_DATA:
HOST: xxx
PORT: xxx
USER: xxx
PWD: xxx
I need to write CONNECTION_DATA with its nested elements into a yaml file. For this I use the following task:
vars:
CONNECTION_DATA:
HOST: xxx
PORT: xxx
USER: xxx
PWD: xxx
tasks:
- name: Writing vars to file yaml
ansible.builtin.copy:
dest: /tmp/vars.yml
content: "{{ CONNECTION_DATA | to_nice_yaml }}"
Only problem is this outputs to:
HOST: xxx
PORT: xxx
USER: xxx
PWD: xxx
Instead I would like to have:
CONNECTION_DATA:
HOST: xxx
PORT: xxx
USER: xxx
PWD: xxx
Is there a workaround to achieve this?