# Declare local file argument for module

**URL:** <https://forum.ansible.com/t/declare-local-file-argument-for-module/18090>\
**Category:** Ansible Developer\
**Created:** [April 26, 2015, 11:25am UTC](https://forum.ansible.com/t/declare-local-file-argument-for-module/18090 "2015-04-26T11:25:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michail\_Alexakis](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@Michail\_Alexakis](https://forum.ansible.com/u/Michail_Alexakis)\
**Post date:** [April 26, 2015, 11:25am UTC](https://forum.ansible.com/t/declare-local-file-argument-for-module/18090/1 "2015-04-26T11:25:00Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [April 26, 2015, 3:03pm UTC](https://forum.ansible.com/t/declare-local-file-argument-for-module/18090/2 "2015-04-26T15:03:42Z")

</div>

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](https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action_plugins/copy.py)

---

<div class="post-metadata">

**Author:** ![Michail\_Alexakis](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@Michail\_Alexakis](https://forum.ansible.com/u/Michail_Alexakis)\
**Post date:** [April 26, 2015, 3:42pm UTC](https://forum.ansible.com/t/declare-local-file-argument-for-module/18090/3 "2015-04-26T15:42:06Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 27, 2015, 5:04pm UTC](https://forum.ansible.com/t/declare-local-file-argument-for-module/18090/4 "2015-04-27T17:04:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michail\_Alexakis](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@Michail\_Alexakis](https://forum.ansible.com/u/Michail_Alexakis)\
**Post date:** [April 27, 2015, 5:21pm UTC](https://forum.ansible.com/t/declare-local-file-argument-for-module/18090/5 "2015-04-27T17:21:01Z")

</div>

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”))
