I have some continuous integration checks which run a few ansible-playbook
commands. Each playbook may be running many plays, including numerous large roles.
Every now and then, somebody introduces some change that causes a warning when ansible-playbook
runs, e.g. something like this:
[WARNING]: when statements should not include jinja2 templating delimiters
such as {{ }} or {% %}. Found: "{{ some_variable}}" not in
some_result.stdout
or:
[WARNING]: Consider using unarchive module rather than running tar
or some deprecation warnings like:
[DEPRECATION WARNING]: ec2_facts is kept for backwards compatibility but usage
is discouraged. The module documentation details page may explain more about
this rationale.. This feature will be removed in a future release. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
and so on. Sometimes these warnings pop up when we upgrade ansible versions. Regardless of why they happen, I would really like for some way to have the ansible-playbook
command fail loudly when it causes one of these warnings, instead of quietly proceeding on and having my CI check be successful. Is there any way to do this? I'm using ansible 2.4.3 currently.
I find lots of discussion about ways to hide these warnings, but haven't found anything about promoting them to hard errors.
You can use ignore_errors to continue on in spite of the failure. The ignore_errors directive only works when the task is able to run and returns a value of 'failed'. It does not make Ansible ignore undefined variable errors, connection failures, execution issues (for example, missing packages), or syntax errors.
warnings can be disabled by setting deprecation_warnings=False in ansible. cfg.
Error Handling In ansible Playbooks If the task failure also it will go for next task and if the task success also it will go for execution next task. So if you mention ignore_errors=true in any task ansible will go for execution of next task with out taking care of the task result.
Ansible changed_when property or parameters is defined to deal with the output of the specific task once a task is triggered on the remote node and based on the return code or the output, we can determine whether the task should be reported in the ansible statistic or need to use the trigger to handle the condition and ...
I have the exact same problem. My workaround is:
I know it is not ideal, so if you came with a nice solution please share :-)
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