regex_findall doesn't work for me. What am i doing wrong?

46 views
Skip to first unread message

Vikram S

unread,
Apr 9, 2021, 8:43:05 AM4/9/21
to Ansible Project

Hi,

I wrote a script to check if particular IOS version is set as boot statement. But it doesn't work. What am i doing wrong?

name: Gather show boot

ios_command:

commands: "show boot"

register: show_boot

debug:

msg: "{{ 'show_boot.stdout' | regex_findall('c2960x-universalk9-mz.152-7.E3.bin') }}"


Also another objective is match number of boot statements set to number of stacked switches so that i can ensure all stacked switches have the correct boot statement set. So iam trying to match number of times IOS image is set in 'show boot' output to number of times a switch is in 'ready' state in 'show switch' output. 

Below is a login i have come up with but not sure if this will work? Please give your suggestion for improvement if any?

msg: "{{ 'show_boot.stdout' | regex_findall('c2960x-universalk9-mz.152-7.E3.bin') | length }}" == msg: "{{ 'show_switch.stdout' | regex_findall('ready') | length }}"

Dick Visser

unread,
Apr 9, 2021, 11:55:58 AM4/9/21
to ansible...@googlegroups.com
On Fri, 9 Apr 2021 at 14:43, Vikram S <vikrams...@gmail.com> wrote:

Hi,

I wrote a script to check if particular IOS version is set as boot statement. But it doesn't work. What am i doing wrong?


I don't know. What does "it doesn't work" mean in this context?
Put differently, what would make you say "it works"?

What this comes down to is some regex matching, but to debug that we need the input which you did not provide.
So, please provide that.

name: Gather show boot

ios_command:

commands: "show boot"

register: show_boot

debug:

msg: "{{ 'show_boot.stdout' | regex_findall('c2960x-universalk9-mz.152-7.E3.bin') }}"


Also another objective is match number of boot statements set to number of stacked switches so that i can ensure all stacked switches have the correct boot statement set. So iam trying to match number of times IOS image is set in 'show boot' output to number of times a switch is in 'ready' state in 'show switch' output. 

Below is a login i have come up with but not sure if this will work? Please give your suggestion for improvement if any?

msg: "{{ 'show_boot.stdout' | regex_findall('c2960x-universalk9-mz.152-7.E3.bin') | length }}" == msg: "{{ 'show_switch.stdout' | regex_findall('ready') | length }}"

--
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/b25a08a2-bc8b-4e53-92cc-a8a7d3c11ebfn%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.
Reply all
Reply to author
Forward
0 new messages