By: Saikrishna Madupu – Sr Devops Engineer
Ansible by Red Hat is the de-facto tool used by organizations for automated configuration management. It is commonly used for use cases around infrastructure deployment and post deployment actions, application deployments, and for infrastructure operations and lifecycle tasks.
In the following blog, we will cover some examples ansible callback plugins, which help us track events around playbook executions. You can use these plugins for notification of task failures, job statuses, etc.
- Stdout plugins
- Other Plugins (also includes notification plugins & aggregate plugins in general)
A complete list of available plugins can be viewed from terminal:
ansible-doc -t callback -l
- This can be configured by adding stdout_callback plugin as a parameter in your ansible.cfg under defaults section. These plugins are limited to use one at a time.
[defaults] stdout_callback = actionable
- Some stdout_plugins are listed below:
|debug||Readable stderr & stdout|
|Dense||Overwrite o/p rather than scrolling|
|Minimal||Task details with proper format|
|Selective||o/p for tagged task|
|Skippy||Doesn’t show o/p for skipped hosts|
|Oneline||Similar to Minimal but in one line|
Examples of usage:
This plugin is deprecated.
- community.general.actionable has been removed. Use the ‘default’ callback plugin with ‘display_skipped_hosts = no’ and ‘display_ok_hosts = no’ options. This feature was removed from community.general in version 2.0.0. Please update your playbooks.
By enabling debug plugin we don’t need to register output and use again debug module in our playbooks.
Displays standard error in human readable format
It overwrites o/p and only shows two lines as shown below.
Prints o/p in json format and we see the entire o/p.
It is quite similar to default,
Selective plugin shows o/p for tasks that got executed successfully that are tagged with print_action
It doesn’t show o/p for the tasks that got skipped, when a task is not executed for any sort of host it will not be displayed as skipped likewise default do in cases.
It shows o/p of command in one format as shown below.
- There are several other plugins which can send alerts in case of job failures to slack channels, records job execution time, notifications to Distribution lists (emails), and more. You can also enable and use multiple plugins at the same time.
[defaults] Callback_whitelist = slack, mail
This shows the duration of time took to execute each task.
It can be configured to monitor the job in case of success / failure. Below is the example.
We will receive alerts in email once this playbook gets executed.
Some of the other_plugins are listed below
|Name||Description||Libraries required using pip|
|Foreman||Notifies to Foreman|
|Hipchat||Notifies to HipChat||Prettytable|
|Jabber||Notifies to Jabber||git+https://github.com/ArchipelProject/xmpppy|
|Junit||Write JUnit-formatted to XML file||Junit_xml|
|Log_plays||Log results per hosts|
|Logentries||Notifies to Logentries||Certifi flatdict|
|Logstash||Send results to Logstash||Python-logstash|
|Notifies through email when tasks fail|
|Osx_say||Speak notifications on macOS|
|Profile_tasks||execution time for each task|
|Slack||Notifies to Slack||Prettytable|
|timer||Report total execution time of playbook|
About the Author
|Saikrishna Madupu, Sr. DevOps Engineer|
Sai is an IT professional with experience in DevOps Automation, Configuration Management tools, Container workloads and orchestration of those workloads via Kubernetes. A self-starter, and passionate problem-solver, with a flair for innovative design, with an ability to work towards automation whenever possible. He is an experienced Linux, Cloud data center operations and infrastructure engineer. He worked as a Devops cloud consultant in the past, helping clients in migrate on-prem applications to cloud, and holds certifications for AWS, Terraform, Gitlab, and other technologies.