I am using Ansible to deploy a Django website into my servers (production, staging, etc), and I would like to get a notification (via slack in this case) if and only if any task fails.
I can only figure out how to do it if a specified task fails (so I guess I could add a handler to all tasks), but intuition tells me there has to be an easier and more elegant option.
Basically what I am thinking of is:
---
- hosts: "{{hosts_to_deploy}}"
- tasks:
[...]
- name: notify slack of deploy failure
local_action:
module: slack
token: "{{slack_token}}"
msg: "Deploy failed on {{inventory_hostname}}"
when: # any task failed
I have been diving into the Ansible documentation, specially in the error handling section, and answers here at SO, but I'm struggling to find an answer to my question. So any help will be much appreciated.