I have a playbook that configures a RHEL system and when a host fails for any reason I want to execute a sosreport on the host, without having to run another playbook command. This is different than the question asked here How to continue execution on failed task after fixing error in playbook? . In that they need to manually continue the playbook. I just want to handle errors during the play.
I'm not quite sure how to express that in the playbook. Is there a magic variable I can use to determine if a play failed to create a playbook similar to below?
- hosts: rhel7_64Guest
become: yes
roles:
- role: selinux
tags: selinux
- role: timezone
tags: timezone
- role: dns
tags: dns
- role: sosreport
when: ansible_hosts_failed
tags:
- sosreport
- always