Need assistance to check if config is present in certain order in router

33 views
Skip to first unread message

Vikram S

unread,
May 17, 2021, 10:59:44 PM5/17/21
to Ansible Project

The output of 'sh run | i boot' shows 2 boot statements set in router. But i need to write a script which will check if '........9.16.12.04.SPA.bin' is present specifically in 1st line followed by '.......9.16.06.04.SPA.bin' specifically in 2nd line.

I know to write a script to check if both these lines are persent or not. But my challenge is that i need to check if '........9.16.12.04.SPA.bin' is present specifically in 1st line and so on. How do i do that?

ROUTER#sh run | i boot 
boot system flash bootflash:isr4300-universalk9.16.12.04.SPA.bin boot system flash bootflash:isr4300-universalk9.16.06.04.SPA.bin

Thanks,
Vikram

Dick Visser

unread,
May 17, 2021, 11:38:55 PM5/17/21
to ansible...@googlegroups.com

--
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/bc23196e-8ea6-461f-b1da-f0ffa234347dn%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Vikram S

unread,
May 18, 2021, 9:36:09 AM5/18/21
to Ansible Project

Hi Dick,

Not sure if i misunderstood your suggestion but iam already aware of regex_search but does it help with specificaly ensuring that '........9.16.12.04.SPA.bin' is present specifically in 1st line followed by '.......9.16.06.04.SPA.bin' specifically in 2nd line like in below output?

ROUTER#sh run | i boot 
boot system flash bootflash:isr4300-universalk9.16.12.04.SPA.bin 
boot system flash bootflash:isr4300-universalk9.16.06.04.SPA.bin

Reason for this question is even when i give 'no boot' first and then add boot statement in correct order, the lines interchage in rare cases when i check boot statement. Which means the router will boot up with old image rather than new image after reload since that comes in 1st line.

Thanks,
Vikram

Dick Visser

unread,
May 18, 2021, 12:32:07 PM5/18/21
to ansible...@googlegroups.com
Yes this is possible but having the regex multiline aware 

Vikram S

unread,
May 20, 2021, 12:38:33 AM5/20/21
to Ansible Project
Hi Dick,

I went through example in ansible documentation but was not descriptive enough and searched extensively on internet but didn't find any examples for multiline for ansible.

ROUTER#sh run | i boot 
boot system flash bootflash:isr4300-universalk9.16.12.04.SPA.bin 
boot system flash bootflash:isr4300-universalk9.16.06.04.SPA.bin

Below is a script i wrote using regex_search multiline for checking if '........9.16.12.04.SPA.bin' is present specifically in 1st line followed by '.......9.16.06.04.SPA.bin' specifically in 2nd line. But doesn't work. How should i modify it?

- name: GATHER SHOW VERSION
      ios_command:
        commands: "sh run | i boot"

      register: show_boot

    - debug:
        msg:
        - "{{ show_version.stdout[0] | regex_search('isr4300-universalk9.16.12.04.SPA.bin ', 'isr4300-universalk9.16.06.04.SPA.bin', multiline=True) }}"

Thanks,
Vikram
Reply all
Reply to author
Forward
0 new messages