Declare local file argument for module

Hello list,

I was trying to make my first steps writing an Ansible module (in Python).
The main documentation is pretty clear, so i moved very smoothly using the AnsibleModule helper class.
So far, i have been using only simple arguments: scalars or JSON-serializable structs (lists, dicts etc.).

Now, i need to declare a file argument (say src given as a local path) that is present at Ansible’s control
host and must be transferred to the managed host (and then it will acquire a temporary file name).
This is very similar to what the copy module does: when the module is executed on the managed host
the src argument is just a remote temporary file path (and i assume transfer has already taken place).

I was looking into copy module’s source code (to mimic it and declare such an argument), but i was
not able to figure it out. Is there some kind of magic (control-side pre-execute hooks?) behind the behavior of
modules like copy and template ?

So, my question: does a custom module have the option to transfer a control-side file and handle it (managed-side)
as a normal file path? Or instead, must we break this into 2 tasks (one builtin copy task, one custom task)?

Thank you!

The copy module also uses an action plugin that runs on the controlling
machine to read/transfer the local file:

https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action_plugins/copy.py

Ok, I understand, so i suppose each module that needs some special control-side action needs to have a
corresponding action plugin.

The problem is that i cannot find any relevant documentation at http://docs.ansible.com/developing_plugins.html
for creating an action plugin (besides, of course, the source code itself).

Is this type of plugin is not supposed/encouraged to be developed outside of the core Ansible team?

Not discouraged, but normally not recommended until you've written
some independent modules first. We lack development docs for most
other plugin types, but they are not that hard to do.

Thanks Brian,

So, i suppose my alternatives are

  • prepend a copy task before each module invocation, or
  • replace an src argument with a contents argument filled with the contents of the control-side file (e.g. via lookup(“file”))