awx icon indicating copy to clipboard operation
awx copied to clipboard

Ability to Generate a Failed Host Summary Using Notification Attributes

Open imareporter opened this issue 5 years ago • 3 comments

ISSUE TYPE
  • Feature Idea
SUMMARY

An user is requesting the ability to generate a failed host summary using notification attributes (https://docs.ansible.com/ansible-tower/latest/html/installandreference/notification_parameters_supported.html). The failed host summary would be sent via email.

Ideally, they want a structure similar to this:

Failed Hosts:
<HOSTNAME> failed <TASK_NAME> in <PLAYBOOK_NAME>

There is a job_metadata attribute, which includes all target hosts and their status.

EXAMPLE:

{
  "test1.example.com": {
    "failed": true,
    "changed": 0,
    "dark": 1,
    "failures": 0,
    "ok": 0,
    "processed": 1,
    "skipped": 0,
    "rescued": 0,
    "ignored": 0
  },
  "test2.example.com": {
    "failed": true,
    "changed": 0,
    "dark": 1,
    "failures": 0,
    "ok": 0,
    "processed": 1,
    "skipped": 0,
    "rescued": 0,
    "ignored": 0
  }
}

However, it appears you can't query deeper into the JSON body with filters and grab the necessary information. At this point, all metadata about the job is displayed.

Is it possible to implement a failed host summary with the preceding structure? If not, is it possible to generate a new notification attribute with just failed host information?

Maybe something like this:

EXAMPLE BODY:

Failed Hosts:

{{ job_failed_hosts }}

JSON BODY:

{
  "failed_hosts": {
    "test1.example.com": {
      "failed_task_name": "Gathering Info",
      "playbook": "test.yml"
    },
    "test2.example.com": {
      "failed_task_name": "Gathering Data",
      "playbook": "test.yml"
    }
  }
}

EXAMPLE RENDERED EMAIL:

Failed Hosts:

{
  "failed_hosts": {
    "test1.example.com": {
      "failed_task_name": "Gathering Info",
      "playbook": "test.yml"
    },
    "test2.example.com": {
      "failed_task_name": "Gathering Data",
      "playbook": "test.yml"
    }
  }
}

Any guidance is much appreciated!

imareporter avatar Mar 25 '20 16:03 imareporter

As of now, you can only use data that is on the job record. We'd have to see how interpolating into that data could be done.

wenottingham avatar Mar 27 '20 17:03 wenottingham

Interested to see if we can help moving this forward ? We have the same requirement, we are using webhook but as far as I know it's the same data/vars we can get..

We tested a way filtering the content of job_metadata in a playbook, it worked but we can't use the same filter(from_json) because it's not a "native" jinja filter so it's not available to use in the notification template.. I'll put it here in case someone have a suggestion or another way of filtering the data.

- name: debug debug: msg: | List failed host: {% set job_details = job_metadata | from_json -%} {% for host in job_details.hosts -%} {% if job_details.hosts[host].failed -%} {{ host }} {% endif -%} {% endfor -%}

arsenicks avatar Oct 01 '21 18:10 arsenicks

Anything further on this since 2021? I'd just like to get a list of hosts processed in our AWX webhook notifications.

agouaux avatar Jul 22 '24 13:07 agouaux