Hi,

i need to write a script that will gather the ios image present in cisco 
router/switch and delete it.

Below is the output of command executed on a router for reference and iam 
including this command in script. I used regex to first extract only 
'isr4300-universalk9.03.19.04b.S.155-3.S4b-ext.SPA.bin' from the first line 
of output (by telling it to extract all characters after bootflash/) and 
then save it a custom variable and delete it. However the problem is, when 
i give 'delete /force bootflash:{{ ios_image1 }}' an extra [' .... '] gets 
added which is not supposed to be there. Why does it get added and how do i 
get rid of it?


ROUTER#sh flash: | i SPA.bin

  4  486645440 Nov 12 2018 17:29:44.0000000000 +00:00 
/bootflash/isr4300-universalk9.03.19.04b.S.155-3.S4b-ext.SPA.bin

159  588714445 Jan 09 2021 14:38:08.0000000000 +00:00 
/bootflash/isr4300-universalk9.16.12.06.SPA.bin

180  642363156 Jan 20 2021 14:34:23.0000000000 +00:00 
/bootflash/isr4300-universalk9.16.15.04.SPA.bin


SCRIPT:

 tasks:

  - name: GATHER SHOW VERSION

        ios_command:

          commands: "sh flash: | i SPA.bin"

      register: show_image


      - set_fact:

          ios_image1: "{{ show_image.stdout_lines[0][0] | 
regex_findall('bootflash/(.*)') }}"


    - name: DELETE IMAGE DIRECTORY IN MASTER FLASH IF PRESENT

        ios_command:

          commands: "delete /force bootflash:{{ ios_image1 }}"


OUTPUT:

TASK [DELETE IMAGE DIRECTORY IN MASTER FLASH IF PRESENT] 
*******************************************************************************************************************

fatal: [ROUTERTEST]: FAILED! => {"changed": false, "msg": "delete /force 
bootflash:['isr4300-universalk9.03.19.04b.S.155-3.S4b-ext.SPA.bin']\r\n%Error 
deleting 
bootflash:['isr4300-universalk9.03.19.04b.S.155-3.S4b-ext.SPA.bin'] (No 
such file or directory)\r\nROUTER#"}

----------------------------------------------------------------------------------------------------------------------------------------

I ran below script for verification purpose:

- debug: 

 msg: 

 - "{{ ios_image1 }}"


k: [ROUTERTEST] => {

    "ansible_facts": {

        "ios_image1": [

            "isr4300-universalk9.03.19.04b.S.155-3.S4b-ext.SPA.bin"

        ]

    },

    "changed": false

}


Thanks,

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/64bb33ca-7d14-41d4-b2e1-aa8ec181246en%40googlegroups.com.

Reply via email to