Hi all,
I am writing a ansible playbook which will gather all the failed count from script and after sum it will display in the report.
For example: shell script fails that is called from the ansible fails with exit 1, 2 for different cases with diff error message after the script runs in different hosts.
I want to gather the total number of failed count(exit 1 + exit 2) and display it in stout. Can I use failed_when and changed_when to achieve this? How do I get the sum?
I want to handle this with in ansible to have a better control rather than in shell script. How can I achieve this?
If it's possible, Can anyone provide a small example to achieve this?
Regards
Pradeep
I don't understand what you are trying to do, but can give you answer on how to get the error code.
If you use "register: myvar" on a shell task the variable "myvar.rc" contains the return code.
Since Ansible stops a play on a host when rc > 0 you need to use "failed_when: false" or "ignore_errors: true".
Thanks for your help.
Actually I am already doing that as you suggested. What I need is as follows:
- Shell Script of ansible role → exit 1 for certain condition for m nodes for example
- Shell Script of ansible role → exit 2 for another condition for n nodes for example
Both 1 and 2 are failure condition and it should return in the failed output. But I need to separately show in the fail report. I need to show cumulative report also i.e how many (1) and (2) occurred when the ansible playbook is run. The idea is to sum (1st Condition) +( 2nd Condition) and display the output. I am not sure how I can calculate the sum of failed conditions (m+n). I want to handle this in ansible rather than in shell script returning the list containing the number of counts which is more clean way to handle this. How can I achieve this? If you have any idea please let me know. Any code snippet will help.