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

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 bootboot system flash bootflash:isr4300-universalk9.16.12.04.SPA.bin boot system flash bootflash:isr4300-universalk9.16.06.04.SPA.bin

Thanks,
Vikram

No need for scripts, use the regex_search filter:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#id40

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

Yes this is possible but having the regex multiline aware

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