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?
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?
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
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.
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?
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.
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
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.