Need assistance to run tasks/module on several switch simultaneously (my script currently checks 1 device at a time)

Below is the script i have written to perform MD5 verification for stacked switch 2. Problem with this script is that iam saving output of MD5 verification command to a custom varriable called ‘md5_flash2’ using register and then checking if correct md5 value is present there.

Since iam using register, so only the output of last device will get saved (and over-write previous data) in this custom variable. So iam forced to check MD5 verification for 1 device at a time. Is there any alternate way to write script to do do MD5 verification (and other tasks) simultaneously for several devices?

  • name: DO MD5 VERIFICATION FOR FLASH 2 AND END PLAYBOOK IF IT FAILS

block:

  • ios_command:

commands: “verify /md5 flash2:/c2960x-universalk9-mz.152-7.E3/c2960x-universalk9-mz.152-7.E3.bin”

vars:

ansible_command_timeout: 360

register: md5_flash2

  • debug:

msg: MD5 VERIFICATION IS SUCCESSFUL FOR FLASH 2

when: “‘f148fc860a1d4d08532bc616724e632d’ in md5_flash2.stdout[0]”

  • meta: end_host

when: “‘f148fc860a1d4d08532bc616724e632d’ not in md5_flash2.stdout[0]”

when:

  • “‘Switch 02’ in show_version.stdout[0]”

Hi Vikram,
Find here an ansible role that includes among others a MD5 checksum task, file_check.yml and checksum.py
It is a draft but is working fine.
Best regards
Teo