When conditional not working when i use 'OR' for multiple confitions

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]”)

Thanks,
Vikram

I find this ambiguous.

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)?

Antony.

The - is an implicit AND so you are doing X OR AND Y OR AND Z.

remove the - and make it all one string:

when: - "'Waiting' in print_showswitch.stdout[0]" or
             'Progressing' in print_showswitch.stdout[0]" or
             'Initializing' in print_showswitch.stdout[0]"

Hi Anthony,

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.

Regards,
Vikram

Now I am even more confused.

First you say: "I want to end the playbook if every member switch in a stack
is in some state state other than ready."

So, every switch must be in a state other than ready, for the playbook to end.

One switch in ready state means this is not true, so the playbook continues.

Then you say instead: "every switch needs to be in READY state to proceed
otherwise it's going to cause problem"

So, now every switch must be in ready state for the playbook to proceed.

Any switch which is not in ready state causes the playbook to fail.

The two statements do not match, and it's important that you are clear about
what logic you are trying to implement in order to get the syntax right.

I *think* you probably intend the second state - all switches must be ready,
otherwise you stop, but they're not my switches :slight_smile:

Antony.

Hi Anthony,

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.

Regards,
Vikram

Hi
cloud you help me how to write ansible playbooks for tags, which were used in rds database in aws cloud.

Thanks & regards,

Hi,

I can write a script using tags but don’t have knowledge about AWS. I have written scripts only for IOS and ASA.

Regards,
Vikram