AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Leveraging Ansible Callback Plugins for Enhanced Performance — Video Tutorial

Profiling, Troubleshooting, and Optimizing Resources in Ansible Automation with timer, profile_tasks, and profile_roles Callback Plugins

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • Introduction
  • Understanding Callback Plugins
  • The ansible.cfg File
  • Configuring Callback Plugins in ansible.cfg
  • Benefits of Callback Plugins
  • Links:
  • Playbook code
  • Execution with Callback Plugins
  • Execution without Callback Plugins
  • Conclusion
Introduction Ansible is a powerful open-source automation tool used for configuration management, application deployment, and task automation. To harness the full potential of Ansible, it’s essential to fine-tune its configuration according to your specific needs. In this article, we’ll delve into the `ansible.cfg` file and explore how to optimize Ansible’s performance by utilizing callback plugins. Specifically, we will focus on the `[defaults]` section of the `ansible.cfg` file and the configuration options `callback_whitelist` and `callbacks_enabled`. Understanding Callback Plugins Callback plugins in Ansible are used to customize the output of playbooks and provide additional functionality during playbook execution. They can be configured globally in the `ansible.cfg` file or per-playbook using the `ansible.cfg` setting in a playbook. Callback plugins offer a wide range of capabilities, from generating custom reports to monitoring playbook execution time. The ansible.cfg File The Ansible.cfg file is a central configuration file that governs Ansible’s behavior. It is typically located in the `/etc/ansible/` directory for system-wide configurations or in the project directory for playbook-specific configurations. To modify Ansible’s behavior, you can edit this file to include various settings related to callback plugins. Configuring Callback Plugins in ansible.cfg Within the `ansible.cfg` file, configuration settings for callback plugins are placed in the `[defaults]` section: ```ini [defaults] callbacks_enabled=ansible.posix.timer,ansible.posix.profile_tasks,ansible.posix.profile_roles ``` The `callbacks_enabled` option lists the callback plugins to activate during playbook execution — here the three performance plugins `ansible.posix.timer`, `ansible.posix.profile_tasks`, and `ansible.posix.profile_roles`. These are *aggregate* (non-stdout) callbacks, which must be explicitly enabled before they run. > **Note:** This option was named `callback_whitelist` before ansible-core 2.11. If you are following older guides that use `callback_whitelist=...`, rename it to `callbacks_enabled=...` — they are the same setting and the old name is deprecated. The matching environment variable is `ANSIBLE_CALLBACKS_ENABLED`. Benefits of Callback Plugins Configuring callback plugins in `ansible.cfg` provides several benefits: 1. **Performance Optimization**: Callback plugins like `ansible.posix.timer` allow you to measure the execution time of tasks and roles, helping identify performance bottlenecks in your playbooks. 2. **Profiling Playbooks**: Callbacks such as `ansible.posix.profile_tasks` and `ansible.posix.profile_roles` enable detailed profiling of playbook execution, aiding in troubleshooting and optimization efforts. 3. **Custom Reporting**: Callback plugins can be customized to generate specific reports or logs, making it easier to track the progress of your Ansible automation. 4. **Selective Execution**: By configuring callback plugins,

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 4 min
  • Category: troubleshooting

Topics covered

Related video tutorials