Could you please help me fetch Ansible-Playbook output in a JSON Format. I do get a JSON output if I set stdout_callback variable as "json" in ansible.cfg
But that output is not in realtime. The result is shown when the whole playbook is executed. How can I get the output as soon as a task is executed ?
Best Answer
There are definitely some problems to overcome, but nothing is impossible.
Here is something for you to play with:
Save this as
./callback_plugins/json_cb.py
:And execute your playbook as:
This will print JSON-object for every completed task (ok or failed).
But you are going to feed this into some other tool to parse it, aren't you? So this other tool should understand continuous stream of JSON objects.