Ansible Callbacks

March 12, 2024

—

ansible

Callback plugins change what Ansible does with the events of a playbook run, such as the output it prints. Two built-in ones are handy to find slow steps: timer prints how long the whole playbook took, and profile_roles adds a timestamp to each task and a summary of the time spent per role at the end. They are enabled in ansible.cfg.

Calculate timers for each task and timers by each role at the end of ansible run:

$ cat ansible.cfg
[defaults]
callbacks_enabled = timer,profile_roles
TASK [Gathering Facts] ********************************************************
terça 27 fevereiro 2024  14:52:13 +0000 (0:00:15.978)       0:00:15.988 *******
....
....
....
Playbook run took 0 days, 0 hours, 2 minutes, 5 seconds
terça 27 fevereiro 2024  14:54:02 +0000 (0:00:15.819)       0:02:05.110 *******
===============================================================================
gather_facts ----------------------------------------------------------- 75.83s
prepare ---------------------------------------------------------------- 49.27s
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
total ----------------------------------------------------------------- 125.10s

https://docs.ansible.com/ansible/latest/plugins/callback.html#enabling-callback-plugins