# Display high-level summary of --diff output

**URL:** <https://forum.ansible.com/t/display-high-level-summary-of-diff-output/29238>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [December 11, 2018, 3:29pm UTC](https://forum.ansible.com/t/display-high-level-summary-of-diff-output/29238 "2018-12-11T15:29:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikobelia](https://avatars.discourse-cdn.com/v4/letter/n/e9a140/32.png) [@nikobelia](https://forum.ansible.com/u/nikobelia)\
**Post date:** [December 11, 2018, 3:29pm UTC](https://forum.ansible.com/t/display-high-level-summary-of-diff-output/29238/1 "2018-12-11T15:29:19Z")

</div>

Hi Ansible list,

A quick question about using Ansible effectively in a CI/CD context: I’m wondering about the best way to set up jobs that runs a playbook with `--check --diff` flags, and gives a concise report of what would be affected by applying changes.

The use case I want to do now is that I’m writing a job to deploy monitoring configuration change, and I’d like to provide an at-a-glance view that says “this job will add this 6 lines of JSON to that config file”. Tha’d be useful for checking there aren’t any other stray changes merged into version control but not deployed yet, as a final typo-proofreading opportunity for the person pushing the update, and as an audit log in retrospect.

This seems like other folks might have tried, but I can’t find anything relevant-looking with a google around, so I wanted to check in with this group.

All the building blocks are there:

Running `template` in diff mode gives this kind of info in task output:

`TASK [datadog_agent : Create a configuration file for each Datadog check] ********************************************************************************************************************* `  
ok: [[use1-tst-datadog01.oad-aws.illumina.com](http://use1-tst-datadog01.oad-aws.illumina.com)] =\> (item=process)  
— before: /etc/datadog-agent/conf.d/custom\_mysql\_metrics.d/conf.yaml  
+++ after: /Users/nbailey/.ansible/tmp/ansible-local-83201emVWXJ/tmpOvX8S\_/checks.yaml.j2  
@@ -25,4 +25,5 @@

- test:original

- 
  - test:test-diff

changed: [[use1-tst-datadog01.oad-aws.illumina.com](http://use1-tst-datadog01.oad-aws.illumina.com)] =\> (item=custom\_mysql\_metrics)  
ok: [[use1-tst-datadog01.oad-aws.illumina.com](http://use1-tst-datadog01.oad-aws.illumina.com)] =\> (item=mysql)

And that comes from this return JSON from the task output:

`ok: [use1-tst-datadog01.oad-aws.illumina.com] => { "changed": false, "diff": { "after": { "path": "/etc/datadog-agent/trace-agent.conf" }, "before": { "path": "/etc/datadog-agent/trace-agent.conf" } },`

I could definitely register each task output and construct a big JSON or YAML block to show all changes across all diffs in a role, but that seems like it’d be very clunky:

`

```auto
- name: Create a configuration file for each Datadog check
  become: True
  template:
    src: checks.yaml.j2
    dest: "/etc/datadog-agent/conf.d/{{ item }}.d/conf.yaml"
    owner: "{{ datadog_agent.user | default('dd-agent') }}"
    group: "{{ datadog_agent.group | default('dd-agent') }}"
  with_items: "{{ datadog_agent.checks|list }}"
  notify: restart datadog-agent
  when: datadog_agent is defined
  register: datadog_config_output

- name: If there were changes, save them for later reporting.
  set_fact: {{ false if datadog_config_output.changed == false else do some gnarly logic that involves parsing results for each item }}

```

`

But this seems really labour intensive.

Is this a job for a callback plugin? The ‘log\_plays’ sounds like it’s doing something fundamentally very similar, but the docs are pretty sparse ([https://docs.ansible.com/ansible/2.6/plugins/callback/log\_plays.html](https://docs.ansible.com/ansible/2.6/plugins/callback/log_plays.html)).

Have other Ansible users tried something like this, and if so, what did you go with?

Thanks for any pointers!

Nikki

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 11, 2018, 11:53pm UTC](https://forum.ansible.com/t/display-high-level-summary-of-diff-output/29238/2 "2018-12-11T23:53:31Z")

</div>

A better way to construct the output you want is using a custom  
callback, see the json/junit ones as starting points.

---

<div class="post-metadata">

**Author:** ![nikobelia](https://avatars.discourse-cdn.com/v4/letter/n/e9a140/32.png) [@nikobelia](https://forum.ansible.com/u/nikobelia)\
**Post date:** [December 12, 2018, 12:19pm UTC](https://forum.ansible.com/t/display-high-level-summary-of-diff-output/29238/3 "2018-12-12T12:19:37Z")

</div>

Thank you Brian, those two are much better examples than the callback plugins I was looking at!

Other folks on this list, if you would find something like this useful, I put together a rough proof of concept along with a list of links to docs I found useful explaining callback plugins, and a description of what I want to achieve: [https://github.com/kwerey/ansible-diff-callback](https://github.com/kwerey/ansible-diff-callback). If you have ideas about the best approach to take, feel free to drop me a line here or comment on that repo.
