I have a set of playbooks that do look like
- name: Run test
hosts: tester
roles:
- { role: setup_repos }
- { role: setup_environment }
- { role: install_packages }
- { role: run_tests }
- { role: collect_logs }
The current problem is that all over the first 4 roles we have ignore_errors: true
which is not a good practice as it makes very hard to read the output and to debug.
The only reason why ignore_errors
was abused was because we wanted to be able to perform the collect_logs at the end, regardless the outcome.
How can we refactor this in order to remove the ignore_errors and have a more of a fail-fast strategy.
Please note that we have lots of playbooks calling collect_logs role, so "moving code inside playbook" is not really a way to reuse it.
On ansible 2.4 or newer one should replace
role:
block with tasks likerole_include
orrole_import
, which gives you the ability to use normal logic used by tasks. You could use handlers, ignore_errors, and so on.