So, I want to get --diff to output something useful when using the synchronize module.
As I understand it so far, making a diff for changes entails returning a list of ‘before’ and ‘after’ pairs in result[‘diff’]. These contain the two texts that are actually diffed using python difflib.
What if I have a “diff” already (e.g. rsync --itemize-changes or rsync --out-format=‘%i %n%L’)?
Do I just “print”, or “display.display()” something in case --diff is on? I supposed that isn’t going to get merged if I do it like that.
In current devel (future 2.1.0) modules can check module._diff boolean
property to figure out if they are in diff mode or not, returning a
dictionary with the differences keyed to 'diff' will automatically be
used by the default callbacks to display it.
Yes, but I do not have “before” and “after” texts to feed to diff later. Only a list of files annotated with flags about how they were changed. Basically, if self._diff is True I want to print something to the Ansible output below [changed]. Is that possible?
In current devel (future 2.1.0) modules can check module._diff boolean
property to figure out if they are in diff mode or not, returning a
dictionary with the differences keyed to 'diff' will automatically be
used by the default callbacks to display it.
This sounds interesting, didn't look in detail yet, but in my use cases
(cloudstack modules). I compare [1] values and keys of 2 dicts.I thought
about how I would return the diff in this case.
I came to the conclusion that I would return a dict with all key/values
which are different. What do you think?
I was actually going to do something along these lines (I work with Juniper routers that construct their own diffs and since the files can be quite large, sending before+after for a single line change is kind of silly).
Then, I noticed that the devel (future 2.1.0) callback looks for diff[‘prepared’]. I ended up modifying my Juniper router module to add the router-created diff to diff[‘prepared’] in the response and ansible handles it beautifully.