Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible: promoting warnings to errors

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.

like image 747
Josh Kupershmidt Avatar asked Apr 25 '18 20:04

Josh Kupershmidt


People also ask

How do you handle error in Ansible?

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.

How do I ignore warnings in Ansible?

warnings can be disabled by setting deprecation_warnings=False in ansible. cfg.

What happens when one playbook fails a task?

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.

What is Changed_when in Ansible?

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


1 Answers

I have the exact same problem. My workaround is:

  • run the playbook with --check and 'tee' to a temporary file
  • do some grep-magic to filter out 'WARNING]:'
  • do some grep-sed-magic to filter out results that are not zero (except ok/skipped)

I know it is not ideal, so if you came with a nice solution please share :-)

like image 155
droperto Avatar answered Sep 21 '22 16:09

droperto