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

**URL:** <https://forum.ansible.com/t/need-assistance-to-check-if-config-is-present-in-certain-order-in-router/35185>\
**Category:** Ansible Project\
**Created:** [May 18, 2021, 2:59am UTC](https://forum.ansible.com/t/need-assistance-to-check-if-config-is-present-in-certain-order-in-router/35185 "2021-05-18T02:59:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [May 18, 2021, 2:59am UTC](https://forum.ansible.com/t/need-assistance-to-check-if-config-is-present-in-certain-order-in-router/35185/1 "2021-05-18T02:59:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 18, 2021, 3:38am UTC](https://forum.ansible.com/t/need-assistance-to-check-if-config-is-present-in-certain-order-in-router/35185/2 "2021-05-18T03:38:28Z")

</div>

No need for scripts, use the regex\_search filter:  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html#id40](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#id40)

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [May 18, 2021, 1:36pm UTC](https://forum.ansible.com/t/need-assistance-to-check-if-config-is-present-in-certain-order-in-router/35185/3 "2021-05-18T13:36:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 18, 2021, 4:31pm UTC](https://forum.ansible.com/t/need-assistance-to-check-if-config-is-present-in-certain-order-in-router/35185/4 "2021-05-18T16:31:38Z")

</div>

Yes this is possible but having the regex multiline aware

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [May 20, 2021, 4:38am UTC](https://forum.ansible.com/t/need-assistance-to-check-if-config-is-present-in-certain-order-in-router/35185/5 "2021-05-20T04:38:33Z")

</div>

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
