Score:1

Pass 'ansible_failed_result' variable to Tower Notification

gw flag

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

Score:0
gw flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.