Add ansible.cfg file to better handle Ansible ouput
pierrepo opened this issue · comments
Pierre Poulain commented
For instance:
# https://docs.ansible.com/ansible/latest/reference_appendices/config.html
[defaults]
# https://docs.ansible.com/ansible/latest/plugins/callback/profile_tasks.html
callback_whitelist = profile_tasks
# Use the YAML callback plugin.
stdout_callback = yaml
# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True
Jeremy Tuloup commented
This looks like a good default to have 👍
Pierre Poulain commented
By default, Ansible does not print the time taken by each task:
$ ansible-playbook site.yml -i hosts -u ubuntu
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
ok: [51.83.15.159]
TASK [Install required system packages] ****************************************************************
ok: [51.83.15.159] => (item=apt-transport-https)
ok: [51.83.15.159] => (item=ca-certificates)
ok: [51.83.15.159] => (item=curl)
ok: [51.83.15.159] => (item=software-properties-common)
ok: [51.83.15.159] => (item=python3-pip)
ok: [51.83.15.159] => (item=virtualenv)
ok: [51.83.15.159] => (item=python3-setuptools)
TASK [Add Docker GPG apt Key] **************************************************************************
ok: [51.83.15.159]
TASK [Add Docker Repository] ***************************************************************************
ok: [51.83.15.159]
TASK [Update apt and install docker-ce] ****************************************************************
ok: [51.83.15.159]
TASK [Install Docker Module for Python] ****************************************************************
ok: [51.83.15.159]
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
ok: [51.83.15.159]
TASK [Install extra system packages] *******************************************************************
ok: [51.83.15.159] => (item=jq)
ok: [51.83.15.159] => (item=tree)
TASK [Install ctop] ************************************************************************************
ok: [51.83.15.159]
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
ok: [51.83.15.159]
TASK [Install required system packages] ****************************************************************
ok: [51.83.15.159] => (item=curl)
ok: [51.83.15.159] => (item=python3)
ok: [51.83.15.159] => (item=python3-dev)
ok: [51.83.15.159] => (item=python3-pip)
TASK [Download the TLJH installer] *********************************************************************
ok: [51.83.15.159]
TASK [Check if the tljh-plasma is already installed] ***************************************************
ok: [51.83.15.159]
TASK [Upgrade the tljh-plasma plugin first if it is already installed] *********************************
changed: [51.83.15.159]
TASK [Run the TLJH installer] **************************************************************************
changed: [51.83.15.159]
TASK [Set the idle culler timeout to 1 hour] ***********************************************************
changed: [51.83.15.159]
TASK [Set the default memory and cpu limits] ***********************************************************
changed: [51.83.15.159]
TASK [Reload the hub] **********************************************************************************
changed: [51.83.15.159]
TASK [Pull jupyter/repo2docker] ************************************************************************
ok: [51.83.15.159]
PLAY RECAP *********************************************************************************************
51.83.15.159 : ok=19 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Adding
[defaults]
callback_whitelist = profile_tasks
in the file ansible.cfg
provides a timestamp and the duration of each task, with a summary at the end:
$ ansible-playbook site.yml -i hosts -u ubuntu
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
Monday 06 July 2020 21:58:08 +0200 (0:00:00.045) 0:00:00.045 ***********
ok: [51.83.15.159]
TASK [Install required system packages] ****************************************************************
Monday 06 July 2020 21:58:11 +0200 (0:00:02.542) 0:00:02.587 ***********
ok: [51.83.15.159] => (item=apt-transport-https)
ok: [51.83.15.159] => (item=ca-certificates)
ok: [51.83.15.159] => (item=curl)
ok: [51.83.15.159] => (item=software-properties-common)
ok: [51.83.15.159] => (item=python3-pip)
ok: [51.83.15.159] => (item=virtualenv)
ok: [51.83.15.159] => (item=python3-setuptools)
TASK [Add Docker GPG apt Key] **************************************************************************
Monday 06 July 2020 21:58:35 +0200 (0:00:24.437) 0:00:27.025 ***********
ok: [51.83.15.159]
TASK [Add Docker Repository] ***************************************************************************
Monday 06 July 2020 21:58:37 +0200 (0:00:02.400) 0:00:29.425 ***********
ok: [51.83.15.159]
TASK [Update apt and install docker-ce] ****************************************************************
Monday 06 July 2020 21:58:39 +0200 (0:00:01.207) 0:00:30.633 ***********
ok: [51.83.15.159]
TASK [Install Docker Module for Python] ****************************************************************
Monday 06 July 2020 21:58:42 +0200 (0:00:03.418) 0:00:34.052 ***********
ok: [51.83.15.159]
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
Monday 06 July 2020 21:58:44 +0200 (0:00:02.354) 0:00:36.406 ***********
ok: [51.83.15.159]
TASK [Install extra system packages] *******************************************************************
Monday 06 July 2020 21:58:46 +0200 (0:00:01.356) 0:00:37.763 ***********
ok: [51.83.15.159] => (item=jq)
ok: [51.83.15.159] => (item=tree)
TASK [Install ctop] ************************************************************************************
Monday 06 July 2020 21:58:53 +0200 (0:00:06.990) 0:00:44.754 ***********
ok: [51.83.15.159]
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
Monday 06 July 2020 21:58:55 +0200 (0:00:01.718) 0:00:46.472 ***********
ok: [51.83.15.159]
TASK [Install required system packages] ****************************************************************
Monday 06 July 2020 21:58:56 +0200 (0:00:01.323) 0:00:47.796 ***********
ok: [51.83.15.159] => (item=curl)
ok: [51.83.15.159] => (item=python3)
ok: [51.83.15.159] => (item=python3-dev)
ok: [51.83.15.159] => (item=python3-pip)
TASK [Download the TLJH installer] *********************************************************************
Monday 06 July 2020 21:59:10 +0200 (0:00:13.771) 0:01:01.568 ***********
ok: [51.83.15.159]
TASK [Check if the tljh-plasma is already installed] ***************************************************
Monday 06 July 2020 21:59:10 +0200 (0:00:00.810) 0:01:02.378 ***********
ok: [51.83.15.159]
TASK [Upgrade the tljh-plasma plugin first if it is already installed] *********************************
Monday 06 July 2020 21:59:12 +0200 (0:00:01.523) 0:01:03.901 ***********
changed: [51.83.15.159]
TASK [Run the TLJH installer] **************************************************************************
Monday 06 July 2020 21:59:18 +0200 (0:00:06.300) 0:01:10.202 ***********
changed: [51.83.15.159]
TASK [Set the idle culler timeout to 1 hour] ***********************************************************
Monday 06 July 2020 21:59:38 +0200 (0:00:19.964) 0:01:30.167 ***********
changed: [51.83.15.159]
TASK [Set the default memory and cpu limits] ***********************************************************
Monday 06 July 2020 21:59:39 +0200 (0:00:01.183) 0:01:31.350 ***********
changed: [51.83.15.159]
TASK [Reload the hub] **********************************************************************************
Monday 06 July 2020 21:59:41 +0200 (0:00:01.657) 0:01:33.008 ***********
changed: [51.83.15.159]
TASK [Pull jupyter/repo2docker] ************************************************************************
Monday 06 July 2020 21:59:45 +0200 (0:00:03.650) 0:01:36.659 ***********
ok: [51.83.15.159]
PLAY RECAP *********************************************************************************************
51.83.15.159 : ok=19 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Monday 06 July 2020 21:59:46 +0200 (0:00:01.020) 0:01:37.679 ***********
===============================================================================
Install required system packages --------------------------------------------------------------- 24.44s
Run the TLJH installer ------------------------------------------------------------------------- 19.96s
Install required system packages --------------------------------------------------------------- 13.77s
Install extra system packages ------------------------------------------------------------------- 6.99s
Upgrade the tljh-plasma plugin first if it is already installed --------------------------------- 6.30s
Reload the hub ---------------------------------------------------------------------------------- 3.65s
Update apt and install docker-ce ---------------------------------------------------------------- 3.42s
Gathering Facts --------------------------------------------------------------------------------- 2.54s
Add Docker GPG apt Key -------------------------------------------------------------------------- 2.40s
Install Docker Module for Python ---------------------------------------------------------------- 2.35s
Install ctop ------------------------------------------------------------------------------------ 1.72s
Set the default memory and cpu limits ----------------------------------------------------------- 1.66s
Check if the tljh-plasma is already installed --------------------------------------------------- 1.52s
Gathering Facts --------------------------------------------------------------------------------- 1.36s
Gathering Facts --------------------------------------------------------------------------------- 1.32s
Add Docker Repository --------------------------------------------------------------------------- 1.21s
Set the idle culler timeout to 1 hour ----------------------------------------------------------- 1.18s
Pull jupyter/repo2docker ------------------------------------------------------------------------ 1.02s
Download the TLJH installer --------------------------------------------------------------------- 0.81s
Pierre Poulain commented
Also adding
# Use the YAML callback plugin.
stdout_callback = yaml
# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True
in the the configuration file ansible.cfg
, format outputs in a more readable way.
Without:
$ ansible-playbook quotas.yml -i hosts -u ubuntu --tags discover
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
ok: [51.83.15.159]
TASK [List mounted devices on hosts] *******************************************************************
changed: [51.83.15.159]
TASK [Print mounted devices on hosts] ******************************************************************
ok: [51.83.15.159] => {
"msg": "LABEL=cloudimg-rootfs / ext4 usrquota,grpquota 0 0\nLABEL=UEFI\t/boot/efi\tvfat\tdefaults\t0 0 "
}
PLAY RECAP *********************************************************************************************
51.83.15.159 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
With:
$ ansible-playbook quotas.yml -i hosts -u ubuntu --tags discover
PLAY [all] *********************************************************************************************
TASK [Gathering Facts] *********************************************************************************
Monday 06 July 2020 22:03:59 +0200 (0:00:00.047) 0:00:00.047 ***********
ok: [51.83.15.159]
TASK [List mounted devices on hosts] *******************************************************************
Monday 06 July 2020 22:04:01 +0200 (0:00:02.509) 0:00:02.557 ***********
changed: [51.83.15.159]
TASK [Print mounted devices on hosts] ******************************************************************
Monday 06 July 2020 22:04:02 +0200 (0:00:00.681) 0:00:03.238 ***********
ok: [51.83.15.159] =>
msg: |-
LABEL=cloudimg-rootfs / ext4 usrquota,grpquota 0 0
LABEL=UEFI /boot/efi vfat defaults 0 0
PLAY RECAP *********************************************************************************************
51.83.15.159 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Monday 06 July 2020 22:04:02 +0200 (0:00:00.035) 0:00:03.274 ***********
===============================================================================
Gathering Facts --------------------------------------------------------------------------------- 2.51s
List mounted devices on hosts ------------------------------------------------------------------- 0.68s
Print mounted devices on hosts ------------------------------------------------------------------ 0.04s