Ansible Callback Plugins: Customize Output, Logging, and Notifications
By Luca Berton · Published 2024-01-01 · Category: installation
Master Ansible callback plugins to customize playbook output, enable logging, send notifications, and track performance. Built-in callbacks, custom plugin development, and integration with monitoring systems.
What Are Callback Plugins?
Callback plugins hook into Ansible's event system to react to playbook events — task start, task success, task failure, play end, etc. They control what you see on screen, where logs go, and what notifications fire.
Every time you run ansible-playbook, a callback plugin formats the output you see. The default is ansible.builtin.default. But there are dozens of alternatives.
Built-in Callback Plugins
Enable Callbacks
Output Format Callbacks (stdout)
Only one stdout callback can be active at a time:
YAML callback (recommended for daily use):
JSON callback (for CI/CD parsing):
Performance Profiling Callbacks
timer — Total playbook execution time:
profile_tasks — Per-task timing (sorted slowest first):
profile_roles — Per-role timing:
Logging Callbacks
log_plays — Logs play output to files per host in a directory.
mail — Send email on task failure:
Notification Callbacks
slack — Post results to Slack:
Custom Callback Plugin
Basic Structure
Webhook Callback (Teams, Discord, PagerDuty)
ARA Records Ansible
ARA is a callback plugin that records playbook runs to a database and provides a web UI for browsing history:
Callback Types
| Type | Description | Example | |------|-------------|---------| | stdout | Controls terminal output (only one active) | yaml, json, minimal | | notification | Sends alerts/notifications | slack, mail, webhook | | aggregate | Collects and aggregates data | timer, profile_tasks |
Use in CI/CD
FAQ
How do I see which callbacks are available?
Run ansible-doc -t callback -l to list all installed callback plugins. Use ansible-doc -t callback yaml to see documentation for a specific plugin.
Can I use multiple stdout callbacks?
No. Only one stdout callback can be active. But you can use multiple notification and aggregate callbacks simultaneously. Set stdout_callback for output format and callbacks_enabled for additional plugins.
How do I write task output to a file AND show it on screen?
Use the default stdout callback for screen output and add log_path in ansible.cfg for file logging. Or use ARA for structured recording plus any stdout callback.
Why isn't my custom callback loading?
Check: (1) file is in callback_plugins/ directory or DEFAULT_CALLBACK_PLUGIN_PATH, (2) CALLBACK_NEEDS_ENABLED = True requires listing in callbacks_enabled, (3) Python syntax is correct (python -c "import my_callback"), (4) class is named CallbackModule.
Conclusion
Callback plugins transform Ansible from a tool with fixed output into a flexible automation platform with custom logging, notifications, and performance monitoring. Start with yaml stdout callback and profile_tasks for visibility, add notification callbacks (Slack, Teams, webhook) for team awareness, and consider ARA for full historical recording. For unique requirements, custom callback plugins are straightforward to write.
Related Articles • Ansible Performance Tuning • Ansible Troubleshooting Guide • Ansible Lint Complete Guide • Ansible CI/CD Pipeline Integration • Ansible Documentation Complete Guide
Category: installation