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.

$ ansible -i hosts \
    -m setup