# How do I enable diff mode when I write a module?

**URL:** <https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029>\
**Category:** Ansible Developer\
**Created:** [August 25, 2014, 9:11am UTC](https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029 "2014-08-25T09:11:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorgen\_Hagg](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@Jorgen\_Hagg](https://forum.ansible.com/u/Jorgen_Hagg)\
**Post date:** [August 25, 2014, 9:11am UTC](https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029/1 "2014-08-25T09:11:10Z")

</div>

I’ve managed to write a module that supports check mode, but it would be nice if it also could display  
the changes it will do, that is, supporting diff mode.

But I can’t find any documentation about the subject.

So, any hints? 🙂

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [August 25, 2014, 9:51am UTC](https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029/2 "2014-08-25T09:51:14Z")

</div>

I believe that is implemented in the action plugin part. Have a look here:

grep self.runner.diff ansible/lib/ansible/runner/action\_plugins/\*

for a starting point

Serge

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 25, 2014, 3:35pm UTC](https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029/3 "2014-08-25T15:35:21Z")

</div>

Yeah, basically you can’t in just an arbitrary module, without an action plugin, but you can copy what the copy module does [sic] 🙂

You’ll note it’s very fiddly.

Another one of the problems with diff mode is if you have more than 1 system, the output starts to get rough to read – couldn’t figure out how to make that nice, really.

---

<div class="post-metadata">

**Author:** ![Jorgen\_Hagg](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@Jorgen\_Hagg](https://forum.ansible.com/u/Jorgen_Hagg)\
**Post date:** [August 26, 2014, 6:23am UTC](https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029/4 "2014-08-26T06:23:36Z")

</div>

Hmm, I was actually hoping for something like returning the diff or the  
old and new value in exit\_json() and then Ansible would format it nicely for me. 🙂

Wouldn’t that be possible?

Anyway, I have not completely figured out exactly what the action plugin  
does and how it is connected to the module, is there any docs on that?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 26, 2014, 11:06pm UTC](https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029/5 "2014-08-26T23:06:03Z")

</div>

Not so possible, the diff stuff was done that way to avoid caching very very large data in internal memory.

Action plugins are covered briefly in the developer docs, though I’d basically just recommend reading some of the simpler ones - like pause or set\_fact, before looking at the very complex ones, like copy or template.

---

<div class="post-metadata">

**Author:** ![Henry\_Finucane](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@Henry\_Finucane](https://forum.ansible.com/u/Henry_Finucane)\
**Post date:** [August 30, 2014, 8:13pm UTC](https://forum.ansible.com/t/how-do-i-enable-diff-mode-when-i-write-a-module/16029/6 "2014-08-30T20:13:10Z")

</div>

> Hmm, I was actually hoping for something like returning the diff or the  
> old and new value in exit\_json() and then Ansible would format it nicely for  
> me. 🙂
> 
> Wouldn't that be possible?

Yes. I wrote up a couple of 'hello world' style action plugins here:  
[https://github.com/locationlabs/ansible-action-plugins](https://github.com/locationlabs/ansible-action-plugins)

The 'pipediff' module and the corresponding 'pipediff' action plugin  
are what you'd be interested in.

> Anyway, I have not completely figured out exactly what the action plugin  
> does and how it is connected to the module, is there any docs on that?

> From a user perspective, they're just like modules, but they run

inside of the main Ansible process and can do basically whatever they  
want. Mostly they're used for things like fetch, template, and copy,  
that need to do work on both the control machine and the target.
