Ansible Callback Plugins For Effective Automation in 2025

ansible callback plugins

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Ansible Callback Plugins are a super feature that control how the results are displayed or logged when a playbook runs. They allow you to customise and enhance Ansible communication during execution from printing output to the terminal to sending events to an external system. 

Why Use Ansible Callback Plugins?

Typically, a default callback plugin, prints human-readable output to the terminal, however, if you employee other Ansible callback plugins, you can also use other advanced features, like: 

  • Sending real-time notifications to Slack, email, or webhooks. 
  • Log structured output in JSON or YAML.
  • Track playbook runs with an external system like Splunk or Elasticsearch. 
  • Simplify readability of the output. 

How Callback Plugins Work?

Generally, Ansible Callback Plugins use a Python script to react to a specific event in the playbook lifecycle as playbook_on_start, runner_on_ok, or v2_playbook_on_stats.

They live in:

  • Ansible’s built-in callback plugin directory, or
  • A custom path defined in your ansible.cfg file

You can use one active output plugin (e.g., yaml or json) and many passive plugins (e.g., logging or alerts).

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

Built-in Ansible Callback Plugins

Apart from the default plugin, Ansible does come with multiple other callback plugins as well for different types of customization. 

  1. Default

The default plugin is usually the one that is present in the system, it converts computer script into human-readable output in the terminal. It is generally best for normal use and it presents a clean and readable output. 

  1. Minimal

Minimal callback plugin provides a super brief output, like the task name and result. It is best if you want to reduce the clutter in the CI/ CD pipelines or logs. 

  1. YAML

YAML callback plugin provides the results in YAML format and is best for structured output that is easy to use and parse. 

  1. Json

It does exactly what the name suggests, providing the result in JSON format. If you use external integrations that consume JSON, then it is definitely your best bet! 

  1. Timer

The time callback plugin displays the total playbook execution time and is mainly helpful for benchmarking and performance tuning.  

  1. Profile_tasks

This plugin shows the time that each task took to run. It is mainly useful for profiling playbook performance and identifying slow tasks. 

  1. Slack, mail, and more (notification plugins)

Send playbook results to external systems like:

  • Slack: Messages to a Slack channel
  • Mail: Email alerts
  • Other plugins: Webhooks, Mattermost, Logstash, etc.

Best for real-time notifications or integration with monitoring/reporting tools.

Enabling Ansible Callback Plugins

Once you have selected and downloaded the plugin that is best suited for your needs, you can enable it by following these steps: 

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

To enable a callback plugin in Ansible:

  1. Create a new file or locate an already existing file in either: 
  • Project directory
  • User home directory (~/.ansible.cfg)
  • /etc/ansible/ansible.cfg
  1. Edit the configuration according to your desired plugins: 
  • [defaults]
  • callback_whitelist = timer, profile_tasks, yaml
  • stdout_callback = yaml
  • callback_whitelist: Lists all the non-default (passive) callback plugins to use.
  • stdout_callback: Sets the active plugin that controls how output is printed (e.g., yaml, json, minimal).
  1. Run your playbook and the specified Ansible callback plugins will be used automatically.

Using Third-Party Ansible Callback Plugins

You can also integrate community-developed or in-house Ansible callback plugins by placing them in a custom directory. 

  1. Create a new directory to store third-party callback plugins by mkdir -p ./callback_plugins.
  2. Place the plugin .py file in this directory. 
  3. Update your ansible.cfg to include the custom path:
    [defaults]

callback_plugins = ./callback_plugins

callback_whitelist = my_custom_plugin

  1. Run your playbook and Ansible will detect and use the plugin.

Creating Custom Ansible Callback Plugins

A custom made Ansible callback plugin allows you to hook into the events and execute your desired logic:

  1. Create a Python file, such as my_callback.py in your callback plugin directory. 
  2. Basic structure:

from ansible.plugins.callback import CallbackBase

class CallbackModule(CallbackBase):

    CALLBACK_VERSION = 2.0

    CALLBACK_TYPE = ‘notification’

    CALLBACK_NAME = ‘my_custom_plugin’

    def v2_runner_on_ok(self, result):

        host = result._host

        print(f”[{host.name}] Task succeeded: {result.task_name}”)

  1. Make sure it’s executable and placed in the directory specified in callback_plugins in ansible.cfg.
  2. Whitelist it in ansible.cfg:

callback_whitelist = my_custom_plugin

Troubleshooting Ansible Callback Plugin Issues

IssuePossible CauseSolution
Plugin not loadingPlugin not whitelisted or stdout_callback not setAdd plugin to callback_whitelist and/or set stdout_callbackin ansible.cfg
No output from pluginPlugin path not defined or incorrectDefine callback_plugins path in ansible.cfg and ensure plugin is in that directory
ImportError or ModuleNotFoundErrorMissing dependencies or wrong Python pathInstall required modules via pip and ensure Ansible uses the correct Python interpreter
SyntaxError or crash during executionPlugin not following Ansible plugin APIReview and validate plugin code; inherit from CallbackBase and use correct method names
Conflicting output formatsMultiple stdout plugins definedOnly one plugin can be used for stdout_callback; remove duplicates in ansible.cfg
Custom plugin not recognizedIncorrect CALLBACK_NAME or file namingEnsure the class is named CallbackModule and CALLBACK_NAMEmatches filename (without .py)
Plugin not triggeredEvent hook method not implementedImplement the correct callback method (e.g., v2_runner_on_ok, v2_playbook_on_stats) for desired action

Wrapping Up – Ansible Callback Plugins

Ansible callback plugins are one of the most useful tools to control how your playbook outlook will look like. Therefore, whether you are looking to streamline terminal output, log to external systems, or trigger notifications, you can find the right Ansible callback plugin for you! 

Do callback plugins affect playbook logic?

No. They only affect how results and events are reported—they don’t interfere with task execution or results.

How do I enable a callback plugin in Ansible?

Edit your ansible.cfg file and add the plugin name to the callback_whitelist and set the stdout_callback if needed.

Can I use multiple callback plugins at the same time?

Yes. You can use one active output plugin (stdout_callback) and multiple passive plugins for logging or notifications.

Marium Fahim
Hi! I am Marium, and I am a full-time content marketer fueled by an iced coffee. I mainly write about tech, and I absolutely love doing opinion-based pieces. Hit me up at [email protected].
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!