Using the profile module to time Ansible playbook runs


This past weekend I spent some time revamping a few playbooks. One of my playbooks was taking a while to run, and I wanted to see how much actual time was spent in each task. Luckily for me, Ansible has a profiling module to help with this. To enable it, you can add the following directive to the default section in your ansible.cfg configuration file:

callback_whitelist = profile_tasks

Future playbook runs will result in a timestamp being printed for each task:

TASK [pihole : Adding port 53 to firewalld] ***********************************
Saturday 11 April 2020  09:22:27 -0400 (0:00:00.080)       0:00:03.630 ********
ok: [127.0.0.1]

And a global summary will be produced once the playbook completes:

Saturday 11 April 2020  09:22:28 -0400 (0:00:00.326)       0:00:04.486 ********
===============================================================================
Gathering Facts --------------------------------------------------------- 1.09s
pihole : Adding port 53 to firewalld ------------------------------------ 0.53s
pihole : Pulling down the pihole docker image --------------------------- 0.44s
pihole : Creating hosts file -------------------------------------------- 0.39s
pihole : Get list of blacklisted domains -------------------------------- 0.35s
.....

Super useful feature, especially when you are trying to shave time off complex playbook runs.

This article was posted by on 2020-04-11 00:00:00 -0500 -0500