openSUSE / ansible-obs

Some playbooks to operate OBS
1 stars 10 forks source link

Print time in playbook output #88

Closed saraycp closed 1 year ago

saraycp commented 1 year ago

This way we know how long each task takes. Especially helpful for migrations tasks.

Example without time in the output:

PLAY [localhost] ********************************************************************

TASK [Gathering Facts] **************************************************************
ok: [localhost]

TASK [Sleeping for 5s] **************************************************************
changed: [localhost]

TASK [Sleeping for 2s] **************************************************************
changed: [localhost]

PLAY RECAP **************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Same example with time in the output:

PLAY [localhost] ********************************************************************

TASK [Gathering Facts] **************************************************************
Friday 06 October 2023  08:11:53 +0000 (0:00:00.144)       0:00:00.144 ******** 
ok: [localhost]

TASK [Sleeping for 5s] **************************************************************
Friday 06 October 2023  08:11:54 +0000 (0:00:00.859)       0:00:01.004 ******** 
changed: [localhost]

TASK [Sleeping for 2s] **************************************************************
Friday 06 October 2023  08:11:59 +0000 (0:00:05.400)       0:00:06.405 ******** 
changed: [localhost]

PLAY RECAP **************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Friday 06 October 2023  08:12:02 +0000 (0:00:02.291)       0:00:08.696 ******** 
=============================================================================== 
Sleeping for 5s -------------------------------------------------------------- 5.40s
Sleeping for 2s -------------------------------------------------------------- 2.29s
Gathering Facts -------------------------------------------------------------- 0.86s

Testing Tips

Create a new sandbox playbook inside the ansible-obs directory and run it as any other playbook. i.e sandbox.yml with content like this:

---
- hosts: localhost
  tasks:
    - name: Sleeping for 5s
      command: sleep 5

    - name: Sleeping for 2s
      command: sleep 2