Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid having to skip fatal task errors with ansible?

Tags:

ansible

When running ansible playbooks you do often encounter use-cases where a task (usually shell or command) is expected to return error codes.

So far the solution was to register the result and to add ignore_errors: true and to decide later if it was a real error or not.

Now, there is one issue with this: it will mess the logging as you will see red error like

fatal: ...
...ignoring

Is there a way to avoid these so we would not have fake errors in the logs?

like image 535
sorin Avatar asked Dec 19 '22 12:12

sorin


1 Answers

failed_when and changed_when is to help you:

- shell: echo good | grep bad
  register: res
  failed_when: false
  changed_when: false

This will always be good and green despite failed shell command.
You can also define a complex failed_when statement based on registered variable.

like image 130
Konstantin Suvorov Avatar answered Mar 05 '23 17:03

Konstantin Suvorov