copy content module is not readable, how to remove all special character and make it proper text readable

I am able to run this playbook it copies the file to destination folder but it has all the special characters and the text is not in readable format. Any help in formatting the output file?

tasks:

  • name: collect the config facts
    icx_facts:
    gather_subset:

  • config
    register: result

  • debug:
    var: result

  • name: copy the output
    copy:
    content: “{{ result }}”
    dest: “/home/sameer/Documents/icx.txt”
    delegate_to: localhost

I am able to run this playbook it copies the file to destination folder but it has all the special characters and the text is not in readable format. Any help in formatting the output file?

“special characters” is a bit ambiguous.
What do you mean by that? How special are they?
Same goes for “text is not in readable format”. Is the format unreadable for you? Or anyone? Or?

If you provide the output then this will avoid any confusion.

Sorry for being little ambiguous.
Here is the output of my file when I read it. It is all clubbed together with newline \n and no proper formatting.

This is because your data is json formatted, but your debug uses yaml
to display.
It could be as simple as adding the to_nice_yaml filter, i.e.:

   - name: copy the output
     copy:
        content: "{{ result | to_nice_yaml }}"
        dest: "/home/sameer/Documents/icx.txt"
     delegate_to: localhost

Thank you so much that worked like a charm. This was my first successful playbook :slight_smile: