# Pass 'ansible\_failed\_result' variable to Tower Notification

**URL:** <https://forum.ansible.com/t/pass-ansible-failed-result-variable-to-tower-notification/35772>\
**Category:** AWX Project\
**Created:** [September 22, 2021, 3:02pm UTC](https://forum.ansible.com/t/pass-ansible-failed-result-variable-to-tower-notification/35772 "2021-09-22T15:02:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Burtton](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Dave\_Burtton](https://forum.ansible.com/u/Dave_Burtton)\
**Post date:** [September 22, 2021, 3:02pm UTC](https://forum.ansible.com/t/pass-ansible-failed-result-variable-to-tower-notification/35772/1 "2021-09-22T15:02:26Z")

</div>

I’m trying to find a way to use the native Ansible and Tower failure variables and notifications respectively to send an email with the result of a job’s execution output.

So I have a playbook that does something like this:

**rescue:**

**- debug:**  
**msg: “Failure:\n\n{{ansible\_failed\_result | to\_nice\_json}}”**

Which gives me a nice output in Tower

However I’d also like to be able to pass that same output from Tower to an email notification so that I can see in an email the output of a job without having to log into Tower. This means I know from my email right away if it’s a connection timeout or something more serious.

I’ve tried using the customize notifications in Tower and have tried the ‘job.job\_explanation’ field, however that always returns empty.

I tried running the job with increased verbosity, but that didn’t work either.

Any ideas of how to do this?  
At this point I’m not sure I’m even on the right track using the job\_explanation field so any help would be much appreciated!

Thanks,  
Dave

---

<div class="post-metadata">

**Author:** ![Christopher\_Meyers](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Christopher\_Meyers](https://forum.ansible.com/u/Christopher_Meyers)\
**Post date:** [September 24, 2021, 2:49am UTC](https://forum.ansible.com/t/pass-ansible-failed-result-variable-to-tower-notification/35772/2 "2021-09-24T02:49:07Z")

</div>

Job\_explanation isn’t going to be fruitful. Unfortunately we do not save the “magic” ansible\_failed\_result. But it would be cool if we did.

Make a workflow. Have the first job call set\_fact with cacheable set to yes and fact caching turned on in tower. Link the second job as failure only. Attach a notification to the second job and use artifacts in the jinja template  
[https://github.com/ansible/awx/blob/2c7d9320e295520cd4549cbcdc6f441b477593ce/awx/main/models/notifications.py#L287](https://github.com/ansible/awx/blob/2c7d9320e295520cd4549cbcdc6f441b477593ce/awx/main/models/notifications.py#L287)

You might not even need two nodes. I can’t remember if workflows support notifications.

---

<div class="post-metadata">

**Author:** ![Dave\_Burtton](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Dave\_Burtton](https://forum.ansible.com/u/Dave_Burtton)\
**Post date:** [September 27, 2021, 5:23pm UTC](https://forum.ansible.com/t/pass-ansible-failed-result-variable-to-tower-notification/35772/3 "2021-09-27T17:23:53Z")

</div>

Would this be the only way to have custom messages defined in the Playbook bubbled back up to the Tower notification level?

I’m not sure the workflow idea will work for my purposes as I want to implement this in all of my templates - having a bunch of workflows just to send out notifications seems a bit messy

Thanks for the help

---

<div class="post-metadata">

**Author:** ![Christopher\_Meyers](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Christopher\_Meyers](https://forum.ansible.com/u/Christopher_Meyers)\
**Post date:** [September 27, 2021, 5:25pm UTC](https://forum.ansible.com/t/pass-ansible-failed-result-variable-to-tower-notification/35772/4 "2021-09-27T17:25:38Z")

</div>

I think you can do this at a job template level but can’t be sure. You should see artifacts on the job if it has a chance at working.

---

<div class="post-metadata">

**Author:** ![Dave\_Burtton](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Dave\_Burtton](https://forum.ansible.com/u/Dave_Burtton)\
**Post date:** [September 28, 2021, 4:09pm UTC](https://forum.ansible.com/t/pass-ansible-failed-result-variable-to-tower-notification/35772/5 "2021-09-28T16:09:16Z")

</div>

Thanks Chris,

I got it working mostly how I’d like which is a great improvement so far! Few more questions but that’s for another post

In case anyone else stumbles across the same issue, here’s how I did it very simply

tasks:

- block:
- name: Fail Task  
fail:  
msg: ‘Failed’  
when: true

rescue:

- name: set stats  
set\_stats:  
data:  
msg\_body\_1: “This was a test”

You can then use {{ job.artifacts }} in the Tower notifications message section to return the variable you set.
