failed_when sequence logic

Having trouble understanding if there’s a bug in failed_when, or my understanding is incorrect -

a false and a true are OR’ing in a YAML sequence to false:

Fails (failed when evals to true):

`

failed_when:

  • ‘“300 OK” not in command_result.stderr’

`

Passes (failed when evals to false):

`

failed_when:

  • command_result.rc != 0

`

Both together pass (failed when evals to false):

`

failed_when:

  • ‘“300 OK” not in command_result.stderr’
  • command_result.rc != 0

`

Spent an hour going back a forth trying to find a syntax error. failed_when passes the task when it evaluates to false, I’ve seen a post from Michael DeHaan saying sequences are treated like ORs.

What am I not seeing?

When you give when, changed_when or failed_when a list, the items are ANDed, not ORed.

Simplified, I’ve tried:

failed_when:

  • true
  • false

evals to false. Surely a bug?

This is the post where sequences are said to evaluate as OR
https://groups.google.com/d/msg/ansible-project/cIaQTmY3ZLE/c5w8rlmdHWIJ

No, pretty sure that is correct, here is the output from the operation of ‘True and False’ in Python:

In [1]: True and False
Out[1]: False

Like I said, they are ANDed not ORed.

If you want to use an or, you are going to have to write it out such as:

failed_when: true or false

Not convinced it’s good syntax, for a failure_when I’d expect an OR.

But ok.

My issue is that I now I want to OR a bunch of multiline statements:

`

failed_when:

“long string with characters that need escaping”
over many $%^&*
lines

and another
long
line

  • etc
  • etc

`

How to OR over multiline sequences?

Ok, got it.

`
failed_when: >
“foo
bar”
not in x or
“baz
bar”
not in y

`

etc. Thanks for the help Matt. Hottest July day on record with no air-con wasn’t helping either :slight_smile: