Notes Ansible module set_stats

Voir :

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/set_stats_module.html

https://docs.ansible.com/ansible-tower/latest/html/userguide/workflows.html

https://stackoverflow.com/questions/49001108/ansible-tower-set-stats-does-not-seem-to-work

https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/set_stats.py

env ANSIBLE_SHOW_CUSTOM_STATS=yes ./playbook.yml -i test-ansible,test-ansible2,

Pour ne pas systématiquement devoir mettre ANSIBLE_SHOW_CUSTOM_STATS=yes il est possible de mettre ce fichier ansible.cfg à la racine du projet (même arborescence que le playbook)

[defaults] show_custom_stats = True
#!/usr/bin/ansible-playbook --- - name: play hosts: all tasks: - name: set stats set_stats: data: var1: plop

CUSTOM STATS: ***********************************************************************************************************************************************
RUN: { "var1": "plopplop"}

#!/usr/bin/ansible-playbook --- - name: play hosts: all tasks: - name: set stats set_stats: data: var1: plop aggregate: no

CUSTOM STATS: ***********************************************************************************************************************************************
RUN: { "var1": "plop"}

Si aggregate: no sur plusieurs machines, la variable est écrasée, c'est la dernière valeur qui l'emporte.

#!/usr/bin/ansible-playbook --- - name: play hosts: all tasks: - name: set stats set_stats: data: var1: plop per_host: yes

CUSTOM STATS: ***********************************************************************************************************************************************
test-ansible: { "var1": "plop"}
test-ansible2: { "var1": "plop"}

Filtrer le set_stats

env ANSIBLE_SHOW_CUSTOM_STATS=yes ./playbook.yml -i inv.yaml | sed -n -e '/CUSTOM STATS:/,/$/p' | sed -e '/CUSTOM STATS:/d' | sed -e 's/[a-zA-Z0-9]*://' | jq .