Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement ignore error result if output contains something in ansible?

Tags:

ansible

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.

like image 614
sorin Avatar asked Mar 14 '23 04:03

sorin


1 Answers

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

like image 64
udondan Avatar answered Apr 06 '23 12:04

udondan