<p>I had to add this to <code>ansible.cfg</code></p>
<pre class="lang-ini prettyprint-override"><code>[defaults]
;inventory = ...
load_callback_plugins = 1 
callbacks_enabled = json
stdout_callback = json
bin_ansible_callbacks = 1
``
</code></pre>

CC BY-SA 4.0
2024-12-10T10:00:26.250Z
2024-12-10T10:00:26.250Z
knb
<p>This is done using one of the configuration options. For a general overview of configuring Ansible, see <a href="https://docs.ansible.com/ansible/latest/reference_appendices/config.html" rel="noreferrer">the configuration documentation</a>, in particular the <a href="https://docs.ansible.com/ansible/latest/plugins/callback.html" rel="noreferrer">callback plugin configuration</a>.</p>
<p>Callback plugins change how Ansible provides feedback on the progress and state of tasks. There are several options for JSON output:</p>
<ol>
<li><a href="https://docs.ansible.com/ansible/latest/plugins/callback/json.html" rel="noreferrer">JSON output to stdout</a></li>
<li><a href="https://docs.ansible.com/ansible/latest/plugins/callback/syslog_json.html" rel="noreferrer">JSON to syslog</a></li>
</ol>
<p>Setting these configuration options can be done either in a configuration file (<code>ansible.cfg</code>) or with environment variables (<code>ANSIBLE_XXX</code>), depending on what you prefer.
To quote the current documentation:</p>
<blockquote>
<p>Changes can be made and used in a configuration file which will be searched for in the following order:</p>
</blockquote>
<blockquote>
<pre><code>   ANSIBLE_CONFIG (environment variable if set)
   ansible.cfg (in the current directory)
   ~/.ansible.cfg (in the home directory)
   /etc/ansible/ansible.cfg
</code></pre>
</blockquote>
<blockquote>
<p>Ansible will process the above list and use the first file found, all others are ignored.</p>
</blockquote>
<p>Assuming you want to send the output to stdout then, your <code>ansible.cfg</code> could look like:</p>
<pre><code>[defaults]
callback_whitelist=json
stdout_callback=json
</code></pre>
<p>Using environment variables:</p>
<pre><code> ANSIBLE_CALLBACK_WHITELIST=json ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...
</code></pre>

CC BY-SA 4.0
2020-08-16T23:14:48.073Z
Appreciate your help!
CLJ
CC BY-SA 4.0
2023-10-13T13:09:31.307Z
If instead of ansible-playbook you want to use the `ansible` ad-hoc CLI, make sure to also set `ANSIBLE_LOAD_CALLBACK_PLUGINS=1`.
Carl Walsh
CC BY-SA 4.0
2023-10-13T13:11:34.537Z
In 2021, ansible 2.11 deprecated the "whitelist" variable and instead renamed it to "enabled" i.e. `ANSIBLE_CALLBACKS_ENABLED`. But I think JSON is enabled by default now.
Carl Walsh
CC BY-SA 4.0
2020-08-15T15:13:10.283Z
2020-08-15T15:13:10.283Z
Bruce Becker
<p>Looking for information on how to output machine readable output form ansible-playbook.</p>

<ansible>
How do I make ansible-playbook log its output in a machine readable format like xml or json?
CLJ
# How do I make ansible-playbook log its output in a machine readable format like xml or json?

(Asked by: username_0 on 2020-08-15)

Looking for information on how to output machine readable output form ansible-playbook.

**Tags:** ansible


---

## 2 answers

### Answer by username_2 on 2020-08-15. Score: 6 | Accepted answer

This is done using one of the configuration options. For a general overview of configuring Ansible, see the configuration documentation, in particular the callback plugin configuration.
Callback plugins change how Ansible provides feedback on the progress and state of tasks. There are several options for JSON output:

JSON output to stdout
JSON to syslog

Setting these configuration options can be done either in a configuration file (ansible.cfg) or with environment variables (ANSIBLE_XXX), depending on what you prefer.
To quote the current documentation:

Changes can be made and used in a configuration file which will be searched for in the following order:


   ANSIBLE_CONFIG (environment variable if set)
   ansible.cfg (in the current directory)
   ~/.ansible.cfg (in the home directory)
   /etc/ansible/ansible.cfg



Ansible will process the above list and use the first file found, all others are ignored.

Assuming you want to send the output to stdout then, your ansible.cfg could look like:
[defaults]
callback_whitelist=json
stdout_callback=json

Using environment variables:
 ANSIBLE_CALLBACK_WHITELIST=json ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...

> **Comments:**
> **username_0**: Appreciate your help!  
> **username_3**: If instead of ansible-playbook you want to use the `ansible` ad-hoc CLI, make sure to also set `ANSIBLE_LOAD_CALLBACK_PLUGINS=1`.  
> **username_3**: In 2021, ansible 2.11 deprecated the "whitelist" variable and instead renamed it to "enabled" i.e. `ANSIBLE_CALLBACKS_ENABLED`. But I think JSON is enabled by default now.  

---

### Answer by username_1 on 2024-12-10. Score: 0

I had to add this to ansible.cfg
[defaults]
;inventory = ...
load_callback_plugins = 1 
callbacks_enabled = json
stdout_callback = json
bin_ansible_callbacks = 1
``


---

