0

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
Ryan Currah
  • 1,067
  • 6
  • 15
  • 30
  • There is [a whole chapter on this in Ansible documentation](https://docs.ansible.com/ansible/latest/playbooks_error_handling.html). This is too broad for SO. Also: roles are collections of tasks, they don't fail. – techraf Mar 06 '18 at 17:28
  • I do not agree that it is to broad, maybe I need to phrase my question better. I read that doc and there is nothing there that answers my question. I want to know the status of the overall play so I can take some actions. Very similar to the rescue in a block statement but for entire plays. – Ryan Currah Mar 06 '18 at 17:34
  • You might also [ask for this](https://stackoverflow.com/a/47594064) (you ask "*if a play failed*", but the example suggests roles). That also does not handle when host connection fails. – techraf Mar 06 '18 at 20:18

0 Answers0