I have wrriten below script to check if switch is in state mentioned in WHEN condition and to end playbook if so. But when condition doesn’t work when i use ‘OR’ conditional to check for multiple conditions.
I tried different ways of writing the OR syntax as given below but didn’t work. What am i doing wrong?
SYNTAX 1:
name: GATHER STACK INFO
ios_command:commands: “show switch”
register: print_showswitch
name: END THIS PLAYBOOK IF ALL MEMBER SWITCHES ARE NOT IN READY STATE
meta: end_host
when: - “‘Waiting’ in print_showswitch.stdout[0]” or
“‘Progressing’ in print_showswitch.stdout[0]” or
“‘Initializing’ in print_showswitch.stdout[0]”
SYNTAX 2:
when:
(“‘Waiting’ in print_showswitch.stdout[0]”) or (“‘Progressing’ in print_showswitch.stdout[0]”)
SYNTAX 3:
when:
(“‘Waiting’ in print_showswitch.stdout[0]” or “‘Progressing’ in print_showswitch.stdout[0]”)
Does it mean that you want to end the playbook if every switch is in some
state state other than ready (so, any switch being ready means the playbook
goes ahead), or does it mean that you want to end the playbook if not all
switches are ready (some are, but not all)?
Yes, i want to end the playbook if every member switch in a stack is in some state state other than ready. I am writing script for IOS upgrade and every switch needs to be in READY state to proceed otherwise it’s going to cause problem.
Sorry for the confusion. I mean that ‘any’ switch and not ‘every’ switch.
As i said earlier, every switch needs to be in READY state to proceed otherwise it’s going to cause problem. So i have written the script to check even if 1 switch in the stack is in a state other than READY, then playbook has to end.