How can I export host errors?

Hello,

For over a year, I’ve been working on and off on a pipeline for exporting all sorts of playbook statistics to Azure Log Analytics and then to Grafana. It has been extremely useful in getting a better view of all my Ansible operations.

It works kinda like this:

tasks: 
  - block:
     [ do the thing ]

   always:
     - include_role:
           name: export_playbook_stats

I even wrote a callback plugin to export the task timers to localhost so that they too can be exported as a log.

self.vars_manager.set_host_variable("localhost", 'task_timers', [v for _, v in self.stats.items()])

I have a dashboard that shows all sorts of stats about a play, such as which hosts fail most often, but something is missing: The error message associated with that host.

Adding register to every task is unfeasible. Even more so because a host gets kicked out once if fails the play.

Those error messages are written somewhere, does anyone know where they are and how I can bring them up to the surface of the play so that I may export them?

Thanks,

A callback plugin would be the appropriate way to do this. When ansible executes, all of the outputs are processed by the callback plugin, which then shows/exports that data to some source. The default is to the console, but you could export that data to some other source.

See the callback plugins available here Index of all Callback Plugins — Ansible Community Documentation
Some are similar to your use case, like exporting to splunk, logstash, opentelemetry…You could use those to guide your own plugin that exports to ALA

Also, theres already a plugin for grafana. You may just want to skip ALA and go straight there.

Edit: Actually, theres already a plugin for ALA too community.general.loganalytics callback – Posts task results to Azure Log Analytics — Ansible Community Documentation

1 Like