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


On Thu, 18 Feb 2021 at 18:10, Sameer Nagwekar <sameer.nagwe...@gmail.com> wrote:
>
> 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.
>
> ===================================================================
> more icx.txt
>
> {"ansible_facts": {"ansible_net_gather_subset": ["config", "default"], 
> "ansible_
> net_config": "Current configuration:\n!\nver 08.0.90jT213\n!\nstack unit 1\n  
> mo
> dule 1 icx7150-c12-poe-port-management-module\n  module 2 
> icx7150-2-copper-port-
> 2g-module\n  module 3 icx7150-2-sfp-plus-port-20g-module\n  stack-port 1/3/1\n
> stack-port 1/3/2\n!\n!\n!\n!\n!\nvlan 1 name DEFAULT-VLAN by 
> port\n!\n!\n!\n!\n!
> \n!\n!\n!\n!\n!\n!\n!\n!\naaa authentication web-server default local\naaa 
> authe
> ntication login default local\nip dns domain-list attlocal.net dynamic\nip 
> dns s
> erver-address 192.168.1.254(dynamic)\nip route 0.0.0.0/0 192.168.1.254 
> distance
> 254 dynamic\n!\nusername sameer password 
> .....\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\
> n!\n!\n!\n!\ninterface management 1\n ip address 192.168.1.190 255.255.255.0 
> dyn
> amic\n!\ninterface ethernet 1/3/1\n speed-duplex 1000-full\n!\ninterface 
> etherne
> t 1/3/2\n speed-duplex 1000-full\n!\n!\n!\n!\n!\n!\nno lldp 
> run\n!\n!\n!\n!\n!\n
> !\n!\nend", "ansible_net_version": "08.0.90jT213", "ansible_net_serialnum": 
> "FEK
> 3239N0BM", "ansible_net_model": "Stackable ICX7150-C12-POE", 
> "ansible_net_image"
> : "SPR08090j.bin", "ansible_net_hostname": null, "ansible_net_data": 
> "Copyright
> (c) Ruckus Networks, Inc. All rights reserved.\n    UNIT 1: compiled on Jan  
> 5 2
> 021 at 21:08:45 labeled as SPR08090j\n      (33554432 bytes) from Primary 
> SPR080
> 90j.bin (Non-UFI)\n        SW: Version 08.0.90jT213 \n      Compressed 
> Primary B
> oot Code size = 786944, Version:10.1.14T225 (mnz10114)\n       Compiled on 
> Thu N
> ov 15 12:59:22 2018\n\n  HW: Stackable 
> ICX7150-C12-POE\n========================
> ==================================================\nUNIT 1: SL 1: 
> ICX7150-C12-2X
> 1G POE 12-port Management Module\n      Serial  #:FEK3239N0BM\n      Software 
> Pa
> ckage: ICX7150_BASE_L3_SOFT_PACKAGE   \n      Current License: 2X1G  \n      
> P-A
> SIC  0: type B160, rev 11  Chip 
> BCM56160_B0\n===================================
> =======================================\nUNIT 1: SL 2: ICX7150-2X1GC 2-port 
> 2G M
> odule\n=========================================================================
> =\nUNIT 1: SL 3: ICX7150-2X10GF 2-port 20G 
> Module\n=============================
> =============================================\n 1000 MHz ARM processor ARMv7 
> 88
> MHz bus\n 8192 KB boot flash memory\n 2048 MB code flash memory\n 1024 MB 
> DRAM\n
> STACKID 1  system uptime is 3 hour(s) 1 minute(s) 1 second(s) \nThe system 
> start
> ed at 00:01:53 GMT+00 Sat Jan 01 2000\n\nThe system : started=cold start   
> \n\n=
> =========================================================================\n=====
> =====       WARNING: Boot-monitor version mismatch!!!      
> ==========\n=========
> =   Please use \"show boot-monitor\" command for details 
> ==========\n===========
> ===============================================================\n===============
> =======================================================================\n=======
> ========       WARNING: FI image is not booted from UFI!!!      
> ===============\
> n======  Please download UFI image and reboot the system for full 
> functionality
>  
> ======\n=======================================================================
> ===============", "ansible_net_stacked_models": ["ICX7150-C12-2X1G"], 
> "ansible_n
> et_stacked_serialnums": ["FEK3239N0BM"]}, "failed": false, "changed": false}
> =============================================================================
>
>
> However on the task debug display it shows proper format. This is how I want 
> the text file to be when I read from the file.
>
> TASK [debug] 
> *******************************************************************
> [WARNING]: Persistent connection logging is enabled for 192.168.1.190. This
> will log ALL interactions to /home/sameer/Documents/ansible.log and WILL NOT
> redact sensitive configuration like passwords. USE WITH CAUTION!
> ok: [192.168.1.190] =>
>   result:
>     ansible_facts:
>       ansible_net_config: |-
>         Current configuration:
>         !
>         ver 08.0.90jT213
>         !
>         stack unit 1
>           module 1 icx7150-c12-poe-port-management-module
>           module 2 icx7150-2-copper-port-2g-module
>           module 3 icx7150-2-sfp-plus-port-20g-module
>           stack-port 1/3/1
>           stack-port 1/3/2
>         !
>         !
>         !
>         !
>         !
>         vlan 1 name DEFAULT-VLAN by port
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         aaa authentication web-server default local
>         aaa authentication login default local
>         ip dns domain-list attlocal.net dynamic
>         ip dns server-address 192.168.1.254(dynamic)
>         ip route 0.0.0.0/0 192.168.1.254 distance 254 dynamic
>         !
>         username sameer password .....
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         interface management 1
>          ip address 192.168.1.190 255.255.255.0 dynamic
>         !
>         interface ethernet 1/3/1
>          speed-duplex 1000-full
>         !
>         interface ethernet 1/3/2
>          speed-duplex 1000-full
>         !
>         !
>         !
>         !
>         !
>         !
>         no lldp run
>         !
>         !
>         !
>         !
>         !
>         !
>         !
>         end
>       ansible_net_data: |-
>         Copyright (c) Ruckus Networks, Inc. All rights reserved.
>             UNIT 1: compiled on Jan  5 2021 at 21:08:45 labeled as SPR08090j
>               (33554432 bytes) from Primary SPR08090j.bin (Non-UFI)
>                 SW: Version 08.0.90jT213
>               Compressed Primary Boot Code size = 786944, Version:10.1.14T225 
> (mnz10114)
>                Compiled on Thu Nov 15 12:59:22 2018
>
>           HW: Stackable ICX7150-C12-POE
>         
> ==========================================================================
>         UNIT 1: SL 1: ICX7150-C12-2X1G POE 12-port Management Module
>               Serial  #:FEK3239N0BM
>               Software Package: ICX7150_BASE_L3_SOFT_PACKAGE
>               Current License: 2X1G
>               P-ASIC  0: type B160, rev 11  Chip BCM56160_B0
>         
> ==========================================================================
>         UNIT 1: SL 2: ICX7150-2X1GC 2-port 2G Module
>         
> ==========================================================================
>         UNIT 1: SL 3: ICX7150-2X10GF 2-port 20G Module
>         
> ==========================================================================
>          1000 MHz ARM processor ARMv7 88 MHz bus
>          8192 KB boot flash memory
>          2048 MB code flash memory
>          1024 MB DRAM
>         STACKID 1  system uptime is 3 hour(s) 1 minute(s) 1 second(s)
>         The system started at 00:01:53 GMT+00 Sat Jan 01 2000
>
>         The system : started=cold start
>
>         
> ==========================================================================
>         ==========       WARNING: Boot-monitor version mismatch!!!      
> ==========
>         ==========   Please use "show boot-monitor" command for details 
> ==========
>         
> ==========================================================================
>         
> ======================================================================================
>         ===============       WARNING: FI image is not booted from UFI!!!     
>  ===============
>         ======  Please download UFI image and reboot the system for full 
> functionality  ======
>         
> ======================================================================================
>       ansible_net_gather_subset:
>       - config
>       - default
>       ansible_net_hostname: null
>       ansible_net_image: SPR08090j.bin
>       ansible_net_model: Stackable ICX7150-C12-POE
>       ansible_net_serialnum: FEK3239N0BM
>       ansible_net_stacked_models:
>       - ICX7150-C12-2X1G
>       ansible_net_stacked_serialnums:
>       - FEK3239N0BM
>       ansible_net_version: 08.0.90jT213
>     changed: false
>     failed: false
>
>
> On Wednesday, February 17, 2021 at 4:28:42 PM UTC-8 dick....@geant.org wrote:
>>
>> On Wed, 17 Feb 2021 at 22:09, Sameer Nagwekar <sameer....@gmail.com> wrote:
>>>
>>> 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.
>>
>>
>>>
>>>   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
>>>
>>> --
>>> 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 ansible-proje...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/89b95950-c38d-4efd-9f05-f360fbfa49a7n%40googlegroups.com.
>>
>> --
>> Sent from a mobile device - please excuse the brevity, spelling and 
>> punctuation.
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/e6705677-4815-4375-846a-1abc9d6940f9n%40googlegroups.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwORpAgH7BHe1JtCau4BRYhosp-yTszEzNUCTH3df3zEtQ%40mail.gmail.com.

Reply via email to