Please find the task output below, usually all the jobs go to changed state 
true and the play successfully so i have passed a failed when condition to 
identify the failure 

----------------------------------------------------------------------------------
TASK [Runing mksysb backup] 
****************************************************
changed: [server1]
fatal: [server2]: FAILED! => {"changed": true, "failed_when_result": true, 
"msg": "\nCreating information file (/image.data) for rootvg.\n\nCreating 
list of files to back up \n\nBacking up 153927 
files..............................\n110142 of 153927 files backed up 
(71%)....\n\n0512-003 mksysb may not have been able to archive some 
files.\nThe messages displayed on the Standard Error contained 
additional\ninformation.\n"}

TASK [Copy output to file] 
*****************************************************
changed: [server1 -> localhost)]
------------------------------------------------------------

Failed output


{
  "changed": true,
  "msg": "\nCreating information file (/image.data) for rootvg.\n\nCreating 
list of files to back up \n\nBacking up 153927 
files..............................\n110142 of 153927 files backed up 
(71%)....\n\n0512-003 mksysb may not have been able to archive some 
files.\nThe messages displayed on the Standard Error contained 
additional\ninformation.\n",
  "invocation": {
    "module_args": {
      "name": "server2.mksysb",
      "storage_path": "/backup",
      "exclude_files": true,
      "backup_crypt_files": true,
      "backup_dmapi_fs": true,
      "create_map_files": false,
      "exclude_wpar_files": false,
      "extended_attrs": true,
      "new_image_data": true,
      "software_packing": false,
      "use_snapshot": false
    }
  },
  "_ansible_no_log": null,
  "failed_when_result": true
}

===============================================================================
Sucessfull output

{
  "changed": true,
  "msg": "\nCreating information file (/image.data) for rootvg.\n\nCreating 
list of files to back up \n\nBacking up 88146 
files................\n\n88146 of 88146 files backed up (100%)\n0512-038 
mksysb: Backup Completed Successfully.\n",
  "invocation": {
    "module_args": {
      "name": "server1.mksysb",
      "storage_path": "/backup",
      "exclude_files": true,
      "backup_crypt_files": true,
      "backup_dmapi_fs": true,
      "create_map_files": false,
      "exclude_wpar_files": false,
      "extended_attrs": true,
      "new_image_data": true,
      "software_packing": false,
      "use_snapshot": false
    }
  },
  "_ansible_no_log": null,
  "failed_when_result": false
}

--------------


On Monday, 27 February 2023 at 01:17:32 UTC+5:30 Dick Visser wrote:

> Clearly your when condition doesn't match. But in order to know why, we'd 
> need to see the content of a failed backup, and maybe a sample success 
> output as well. 
> So post that/those.  
>
> On Sun, 26 Feb 2023 at 16:32, Kenady Inampudi <[email protected]> wrote:
>
>> I am trying to create a report of failed servers output.
>>
>> Here is my playbook
>> ---
>> - hosts: all
>>   gather_facts: no
>>   tasks:
>>     - name: "Runing mksysb backup"
>>       mksysb:
>>         name: "{{inventory_hostname}}.mksysb"
>>         storage_path: /backup
>>         exclude_files: yes
>>       register: mksys
>>       failed_when: '"mksysb: Backup Completed Successfully" not in 
>> mksys.msg'
>>     - name: Copy output to file
>>       copy:
>>        dest: /home/user1/mksysb_error_report.out
>>        content: |-
>>          {% for host in ansible_play_hosts_all %}
>>          {{ '###' }}{{ host }}{{ '###' }}
>>  {{ '------------------------------------' }}
>>          {{ hostvars[host]['mksys']['msg'] }}
>>          {% endfor %}
>>   run_once: True
>>   delegate_to: localhost
>>
>> This gives me output of all the hosts, where i am looking to create the 
>> output of failed hosts 
>>
>> i tried something like this which gives me nothing 
>>
>>          {% for host in ansible_play_hosts_all %}
>>        * {% if 'Completed Successfully' in 
>> hostvars[host]['mksys']['msg'] %}*
>>          {{ '###' }}{{ host }}{{ '###' }}
>>  {{ '--------------------------' }}
>>          {{ hostvars[host]['mksys']['msg'] }}
>>  *{% endif %}*
>>          {% endfor %}
>>
>> Could some help me out to put condition so i can get the output of just 
>> the failed hosts.
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/e7637b0d-400c-4d95-aa99-edcd7c49f5ddn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/e7637b0d-400c-4d95-aa99-edcd7c49f5ddn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> -- 
> Sent from Gmail Mobile
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5435d9a6-4b7d-4129-b558-d457c28b231cn%40googlegroups.com.

Reply via email to