Resolved: ansible: Retry a task based on content of task’s result.stderr

In this post, we will see how to resolve ansible: Retry a task based on content of task’s result.stderr

Question:

I am looking for a solution to the following situation: I automate machine provisioning in my homelab with the help of ansible. Given a poor network connection I want to make my playbooks a bit more robust against (short) network outages.
Now imagine a task like this:
That task occasionally fails. Now, in that case, I want to check the _result object’s stderr for common known errors regarding network issues and retry the task only if it fails because of network issues. Like so:
But this will of cause raise an exception if the task completes without issues and stderr is not present.
Checking stderr to be present before accessing it might be an idea but I could not figure out how to do so in a untilcondition.
Do you have any idea?

Best Answer:

Q: “This will raise an exception if the task completes without issues and stderr is not present.”
A: Use the filter default

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com