I have an ansible task that sometimes can fail and I want to ignore its failure if, and only if, the output contains a specific text.
Logic sounds like: if result code != 0 and "xxx" in output succeed, else fail.
Any Ansible task can have a failed_when
option which defines exactly what result makes the task fail. For this to work you first need to register the result of the task which you then can use in the condition in failed_when
.
Logic sounds like: if result code != 0 and "xxx" in output succeed, else fail.
That would look something like this
- some: task
register: myResult
failed_when: myResult.rc == 0 or "xxx" not in myResult.stdout
Docs: Controlling What Defines Failure
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With