Hi Pushparaj,

I made a small modification to your suggestion and wrote the playbook in 
such a way that the number of boot statements set must match with numbr of 
stacked switches. This is to ensure that all stacked switches have boot 
statemtn set. However i am not getting the desired output. What am i doing 
wrong?

  connection: network_cli
  vars:
    ansible_network_os: ios

  tasks:
    - ios_command:
        commands: "show switch"
      register: show_switch
    - debug:
        msg: "{{ 'show_switch' | regex_findall('Switch') | length }}"

  - ios_command:
        commands: "sh boot"
      register: show_boot
    - debug:
        msg: "{{ 'show_boot' | 
regex_findall('flash:/c2960x-universalk9-mz.154-4.E4.bin') | length }}"

- name: END THIS PLAYBOOK WHEN NO. OF BOOT STATEMENT DO NOT MATCH WITH NO. 
OF SWITCHES
      meta: end_host
      when: "{{ 'show_switch' | regex_findall('Switch') | length }} != "{{ 
'show_boot' | regex_findall('flash:/c2960x-universalk9-mz.154-4.E4.bin') | 
length }}"


Thanks,
Vikram
On Sunday, 7 March, 2021 at 5:46:05 am UTC+5:30 rajthecomputerguy wrote:

> You can use  length of stacked serial number in facts so that you can know 
> how many switch the stack has and you can compare length of boot path regex
>
>
>
> ansible_net_stacked_models 
> list / elements=string
> when multiple devices are configured in a stack 
> The model names of each device in the stack
>
> ansible_net_stacked_serialnums 
> list / elements=string
> when multiple devices are configured in a stack 
> The serial numbers of each device in the stack
>
>
> On Fri, Mar 5, 2021, 8:09 PM Vikram S <vikrams...@gmail.com> wrote:
>
>> Hi Pushparaj,
>>
>> Thanks for above config. But i feel above command may partially only 
>> solve my issue feel. I feel i didn't frame the question properly to get the 
>> correct response.
>>
>> I need to write a script to verify that boot statement is automatically 
>> set in ALL member switches of a stacked switch when doing post-copying 
>> verification.
>>
>> But the problem is the script i know checks if boot statement for new 
>> image is set or not. It DOESN'T check if the boot statement is set for ALL 
>> member switches or not. 
>>
>> In other words, in below output, in case if new image is missing for 1 of 
>> the 3 member switches, how can i identify it using a script?   Each switch 
>> may contain different number of stacked switch, so i may not be able to use 
>> pipe length parameter unles i included some conditional (which may make the 
>> script very lengthy)
>>
>> SWITCH#sh boot | i BOOT path-list
>>
>> BOOT path-list : 
>> flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin
>>
>> BOOT path-list : 
>> flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin
>>
>> BOOT path-list : 
>> flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin
>>
>> On Thursday, 4 March, 2021 at 11:18:41 am UTC+5:30 rajthecomputerguy 
>> wrote:
>>
>>> you can use regex to match and pipe length -- that should be equal to 3
>>>
>>> regex_findall("flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin")
>>>   
>>> |  length
>>>
>>>
>>>
>>> On Thu, Mar 4, 2021 at 3:24 AM Vikram S <vikrams...@gmail.com> wrote:
>>>
>>>> When i use below command, it automatically copies image to ALL member 
>>>> switches and sets boot statement by itself.
>>>>
>>>> archive download-sw /leave-old-sw ftp://username:pass...@10.4.1.104
>>>> /c2960x-universalk9-tar.154-4.E4.tar
>>>>
>>>>
>>>> I need to write a script to verify that boot statement is automatically 
>>>> set in ALL member switches of a stacked switch after this copying. But 
>>>> problem is i can easily write it when the boot statement is only 1 line. 
>>>> But when it is in multiple lines as below (3 boot statement for 3 member 
>>>> switches), thenhow can i verify 
>>>> that'flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin'
>>>>  
>>>> exists on every line and not just in 1 or 2 lines?
>>>>
>>>>
>>>> SWITCH#sh boot | i BOOT path-list
>>>>
>>>> BOOT path-list : 
>>>> flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin
>>>>
>>>> BOOT path-list : 
>>>> flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin
>>>>
>>>> BOOT path-list : 
>>>> flash:/c2960x-universalk9-mz.152-4.E7/c2960x-universalk9-mz.154-4.E4.bin
>>>>
>>>> -- 
>>>> 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/a473afb7-a028-4dcb-b22e-3149242db38bn%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/ansible-project/a473afb7-a028-4dcb-b22e-3149242db38bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>>
>>> -- 
>>>
>>> Thanks,
>>>
>>> Pushparaj G
>>>
>>> -- 
>> 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/baaeb194-7326-4ed7-ae81-c790ac7b321bn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/baaeb194-7326-4ed7-ae81-c790ac7b321bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/a5b94683-046a-4bce-a963-177c6969dd42n%40googlegroups.com.

Reply via email to