In most of lengthy execution you might need to know total time taken by any task to perform on remote server.This statistics much needed when you need to figure out most time consuming task in your playbook.
Ansible has built in plugin callback to find out total time taken by each task and total time taken by entire playbook to complete.
How to enable this builtin plugin ?
In /etc/ansible/ansible.cfg make following changes.
[root@siddhesh ~]# egrep '^callback_whitelist' /etc/ansible/ansible.cfg
callback_whitelist = profile_tasks
[root@siddhesh ~]#
Once done then write one simple playbook to perform some tasks on remote server.
In below example I am going to copy one file and create an archive copy of few files on remote server.
[root@siddhesh ~]# ansible-playbook runtime.yml
PLAY [dbserver] *****************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
Thursday 28 May 2020 16:54:28 +0530 (0:00:00.118) 0:00:00.118 **********
ok: [node2.tecgeek.info]
ok: [node1.tecgeek.info]
TASK [copy local directory to remote server] ************************************************************************************************************************
Thursday 28 May 2020 16:54:29 +0530 (0:00:01.458) 0:00:01.576 **********
ok: [node2.tecgeek.info]
ok: [node1.tecgeek.info]
TASK [Create Zip Archive of multiple file] **************************************************************************************************************************
Thursday 28 May 2020 16:54:29 +0530 (0:00:00.319) 0:00:01.896 **********
changed: [node1.tecgeek.info]
changed: [node2.tecgeek.info]
PLAY RECAP **********************************************************************************************************************************************************
node1.tecgeek.info : ok=3 changed=1 unreachable=0 failed=0
node2.tecgeek.info : ok=3 changed=1 unreachable=0 failed=0
Thursday 28 May 2020 16:54:29 +0530 (0:00:00.141) 0:00:02.038 **********
===============================================================================
Gathering Facts --------------------------------------------------------- 1.46s
copy local directory to remote server ----------------------------------- 0.32s
Create Zip Archive of multiple file ------------------------------------- 0.14s
[root@siddhesh ~]#
From above output you can see that, Ansible playbook execution now shows total time taken by every tasks. This playbook took around 2 Sec .038 MiliSec to complete all its tasks.
Out of this 1.46 Sec for Gathering Facts, 0.32 Sec for copying local directory to remote server, 0.14 Sec for creating Zip archive of multiple files.
I hope this information will help you to trace exact time consuming task in your playbook.
Comments