Ansible facts as JSON

While working on our internal Jenkins setup I need to access some facts about the affected servers and post-process them somehow. While the builtin setup module generates all the output that I want, it also generated a lot of extra output that made it invalid JSON.

Turns out, Ansible has something called Stdout callbacks that allow you to register plugins which in turn post-process the whole standard output generated by Ansible.

$ export ANSIBLE_LOAD_CALLBACK_PLUGINS=true
$ export ANSIBLE_STDOUT_CALLBACK=json 
$ ansible -i hosts jenkins-master-01.local.netconomy.net \
    -m setup