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?
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.
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