# Playbook using host groups: Notify slack on failure and fail entire playbook

**URL:** <https://forum.ansible.com/t/playbook-using-host-groups-notify-slack-on-failure-and-fail-entire-playbook/30284>\
**Category:** Ansible Project\
**Tags:** awx\
**Created:** [May 8, 2019, 3:45pm UTC](https://forum.ansible.com/t/playbook-using-host-groups-notify-slack-on-failure-and-fail-entire-playbook/30284 "2019-05-08T15:45:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AllenJB](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@AllenJB](https://forum.ansible.com/u/AllenJB)\
**Post date:** [May 8, 2019, 3:45pm UTC](https://forum.ansible.com/t/playbook-using-host-groups-notify-slack-on-failure-and-fail-entire-playbook/30284/1 "2019-05-08T15:45:41Z")

</div>

Hi,

I’m working on an Ansible (2.7.9) playbook ( [https://gist.github.com/AllenJB/09f54224a8731467548391e0f093ad33](https://gist.github.com/AllenJB/09f54224a8731467548391e0f093ad33) ) to deploy our project via AWX (4.0.0 via docker) and I’m currently trying to achieve the following:

- The playbook should fail completely (and as soon as possible) if there’s any error, including any unreachable hosts
- AND the playbook should always notify Slack of a failure

So far it seems I’ve only been able to achieve one or the other (my obvious attempts to fail all hosts in notify\_failures are not working). The playbook as it stands notifies Slack but then continues on to the lock / build release steps when I purposefully make an inventory item unreachable (change the ssh port to something nothing is running on)

Is there a way I can wrap the entire playbook in a block / rescue while running the items on different host groups? (Where can you use “hosts:” to restrict tasks? Am I right in thinking you can only use hosts: at the top level and not anywhere inside block:? I couldn’t find any examples and the guessed variations I tried didn’t work)

Or is there some other way I can achieve this?

(I’m aware AWX has Slack notifications but they’re not as customizable as I’d like - I’d like to include extra information such as the commit hash)

Thanks in advance

AllenJB
