Three and more conditions in playbook

Hello.

This is possible to add more than 2 conditions like this?

  • shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }}
    with_items: ether_result.results
    when: ether_result is defined and and item.changed and ether_int_status|failed

ether_result and ether_int_status are registered variables.

Yes, this would also be easy for you to test and try on your own too :slight_smile:

You can also do:

  • shell: foo
    when:
  • a == b
  • c == d
  • e == f

And do ands that way, can sometimes be easier to read.

when:

  • ether_result is defined
  • item|changed
  • ether_int_status|failed

This variant not work for me.
This works:

when:

  • ether_result is defined
  • ether_int_status|failed

More than 2 conditions not work…((

“More than 2 conditions not work…((”

There’s nothing in the code that has any bearing on how many conditions there are that makes 2 special, it’s either “single” or “more than one”

That being said, if you can explain what “doesn’t work” looks like and provide a minimal playbook with output, we can try to reproduce what you are seeing.

Thanks!

Thank you.

I found 2 errors in my code: 1 logical and 1 syntax.
Right conditions: