# Options to modify --diff behavior

**URL:** <https://forum.ansible.com/t/options-to-modify-diff-behavior/1158>\
**Category:** Get Help\
**Tags:** playbook, ansible-core\
**Created:** [September 27, 2023, 8:43pm UTC](https://forum.ansible.com/t/options-to-modify-diff-behavior/1158 "2023-09-27T20:43:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 27, 2023, 8:43pm UTC](https://forum.ansible.com/t/options-to-modify-diff-behavior/1158/1 "2023-09-27T20:43:26Z")

</div>

Is it possible to pass options to `ansible-playbook`’s `--diff` processor? In particular, I’d like to have it ignore whitespace changes.

Normally this isn’t an issue, but I’m diffing a rather involved `.conf` file that’s been maintained by hand for years and converting it to be generated from config data via `ansible.builtin.template`. I’m getting to the point where the majority of the differences are due to the inconsistent spacing that’s crept in over the years, but the content is mindnumbingly tedious. It can take a minute or two to verify that a particular section only differs in spacing.

If there’s a way, please, make my day! Thanks.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [September 28, 2023, 6:34am UTC](https://forum.ansible.com/t/options-to-modify-diff-behavior/1158/2 "2023-09-28T06:34:41Z")

</div>

Why don’t you slurp the files and then then convert them into JSON using either the [JC ini parser](https://kellyjonbrazil.github.io/jc/docs/parsers/ini) or the [JC ini duplicate parser](https://kellyjonbrazil.github.io/jc/docs/parsers/ini_dup) via the [JC filter](https://docs.ansible.com/ansible/latest/collections/community/general/jc_filter.html) and then [compare them](https://docs.ansible.com/ansible/latest/collections/ansible/utils/fact_diff_module.html)?

I’d suggest you might also want to consider using [the ini module](https://docs.ansible.com/ansible/latest/collections/community/general/ini_file_module.html) to update the files as this allows comments to be preserved.

FWIW this is the approach I have used for both [PHP](https://github.com/webarch-coop/ansible-role-php) and [MariaDB](https://github.com/webarch-coop/ansible-role-mariadb) roles as both use INI files.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 28, 2023, 11:54am UTC](https://forum.ansible.com/t/options-to-modify-diff-behavior/1158/3 "2023-09-28T11:54:45Z")

</div>

Thanks for the suggestions, @chris . Those are all useful techniques. Another is to set the template `dest:` to a temporary file on the target host and use the native `diff` with appropriate options. That’s what I’m doing now to work around the build-in `diff`’s missing control knobs.

Given that `ansible-playbook` is _already_ doing a `diff` of some sort, giving the user some say in the options used seems a reasonable ask. Evidently that isn’t possible at the moment. Perhaps a feature request is in order.

I’ll mark your comment as the “solution” even though it’s more of a work-around. “No but …” is as good as we can get for now.

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [October 3, 2023, 9:35pm UTC](https://forum.ansible.com/t/options-to-modify-diff-behavior/1158/4 "2023-10-03T21:35:08Z")

</div>

[difflib](https://docs.python.org/3/library/difflib.html) (the library used by most callbacks to compute diffs) generates standard unified diffs but does not really have any options to expose.

A couple of different proofs of concept for calling an external full-featured diff tool are floating around (e.g. [RFE: Option to ignore whitespace difference in --diff mode · Issue #14674 · ansible/ansible · GitHub](https://github.com/ansible/ansible/issues/14674#issuecomment-485997576)) but no one has ever finished the implementations/opened a PR.

---

<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:** [November 2, 2023, 9:35pm UTC](https://forum.ansible.com/t/options-to-modify-diff-behavior/1158/5 "2023-11-02T21:35:41Z")

</div>

Closed on November 2, 2023, 9:35pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
