Make Ansible less noisy

Traditional UNIX commands are designed for maximum efficiency in a way that they do not produce any disturbing output if not necessary. We assume that shell commands succeed and only if they fail we expect some output on stderr. Ansibles default is a little different from that UNIX philosophy but we do not have to go with the default.

It was a couple of years ago when two of my colleagues decided that it was a good thing to install cowsay on the Ansible server. Well, that was funny at first. But I quickly noticed that the whole herd made it difficult to see what was important. It is not that I do not like cows but I wanted those cows back in the barn. My colleagues did not agree with that. We found a simple solution: I added ANSIBLE_NOCOWS=1 to my shell environment.

The good thing is that I learned how to affect Ansibles behaviour with environment variables. Controlling the output goes far beyond enabling or disabling cows.

Ansibles output is managed by callback plugins. We can view a list of available plugins on our system with

ansible-doc -t callback -l

Callback plugins can either be used for stdout or we can run them in the backgrounrd. Obviously there is only one stdout so we can only have one plugin enabled as stdout plugin. However we can add additional plugins that run in the background.

Callback plugins can either be set in ansbile.cfg or by using environment variables. The following example disables screen output, uses speech synthesis and sends the output to logstash.

ANSIBLE_STDOUT_CALLBACK=null ANSIBLE_CALLBACK_WHITELIST=say,logstash ansible-playbook playbook.yml

A list of available plugins can be found here: https://docs.ansible.com/ansible/latest/collections/community/general/index.html Callback plugins are great way to customize Ansible.

‘Father, give us courage to change what must be altered, serenity to accept what cannot be helped, and the insight to know the one from the other.’ - Reinhold Niebuhr

Contact