In below output taken from a cisco switch, i need to extract only 
'c2960x-universalk9-mz.155-4.E1.bin', c2960x-universalk9-mz.155-2a.EX5, 
c2960x-universalk9-mz.155-7.E3 from each line.

I wrote below script to extract using Regex and specified that any text 
after :30 be extractd. But issue is that some switches will have :00 
instead of :30 in below output. In this case, script will fail to extract 
the correct text. Is there any other way to extract only the above 
mentioned info using Regex or any other filter?

*OUTPUT FROM SWITCH:*

017-DIS-2960X#sh flash: | i c2960x-universal

    3  -rwx    24559616   Mar 9 2019 11:02:09 +05:30  
c2960x-universalk9-mz.155-4.E1.bin

    7  drwx         512   Nov 6 2018 17:11:55 +05:30  
c2960x-universalk9-mz.153-2a.EX5

  649  drwx         512   Apr 9 20210 03:54:19 +06:30  
c2960x-universalk9-mz.155-7.E3


*SCRIPT:*

 - name: GATHER PACKAGE FILES IN FLASH

        ios_command: 

          commands: "sh flash: | i c2960x-universal"


        register: show_image_flash


      - set_fact:

          ios_image1: "{{ show_image_flash.stdout_lines[0][0] | 
regex_findall(':30 (.*)') | first }}"


      - set_fact:

          ios_image2: "{{ show_image_flash.stdout_lines[0][1] | 
regex_findall(':30 (.*)') | first }}"


Regards,
Vikram

-- 
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/30cb0e0b-2175-4302-bd2a-af629934dcadn%40googlegroups.com.

Reply via email to