Thanks for your help. 

Actually I am already doing that as you suggested. What I need is as 
follows:

1. Shell Script of ansible role -> exit 1 for certain condition for m nodes 
for example
2. 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.



On Thursday, May 9, 2019 at 1:02:43 AM UTC+5:30, Kai Stian Olstad wrote:
>
> On 02.05.2019 13:56, Bubunia Patra wrote: 
> > 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? 
>
> 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". 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9367c5ed-7b86-4fe3-b6ad-9ab3820946a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to