# New module (draft) for copying files locally.

**URL:** <https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940>\
**Category:** Ansible Developer\
**Created:** [August 4, 2015, 7:57pm UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940 "2015-08-04T19:57:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Taler](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Alexander\_Taler](https://forum.ansible.com/u/Alexander_Taler)\
**Post date:** [August 4, 2015, 7:57pm UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/1 "2015-08-04T19:57:35Z")

</div>

Hello Ansible Devel

I have developed a module for copying files locally on the host,  
while respecting the Ansible --check option and reporting on  
changes.

I would be glad to submit it to Ansible extras modules if it's  
appropriate. I've included a draft version as a gist below.  
Before submitting I would resolve some of the items on the  
"improvements" list.

[https://gist.github.com/alex-deref/dc66a0ca7e1904c30508](https://gist.github.com/alex-deref/dc66a0ca7e1904c30508)

My motivation for this module is to support an Ansible playbook  
for custom software installation that I'm developing.

Alex

---

<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:** [August 4, 2015, 8:00pm UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/2 "2015-08-04T20:00:59Z")

</div>

wouldn't using copy with -local connection work the same?

---

<div class="post-metadata">

**Author:** ![Alexander\_Taler](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Alexander\_Taler](https://forum.ansible.com/u/Alexander_Taler)\
**Post date:** [August 5, 2015, 9:13am UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/3 "2015-08-05T09:13:28Z")

</div>

> wouldn't using copy with -local connection work the same?

I'm using it in amongst remote operations covering several remote  
hosts. If I understand local connection correctly, that would  
mean installing Ansible on each host and transferring a playbook  
to execute. To me it seems more reasonable to execute the copy as  
a specific module remotely.

Additionally, I'm not sure exactly how copy works in local  
connection mode but looking at the code it seems that it might  
copy all files once prior to doing the compare which would be  
inefficient in the case that nothing needs to be done.

Alex

---

<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:** [August 5, 2015, 3:06pm UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/4 "2015-08-05T15:06:13Z")

</div>

ah, misunderstood what you mean by local, there is a feature request  
for adding this feature to the existing copy module

---

<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:** [August 5, 2015, 4:12pm UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/5 "2015-08-05T16:12:32Z")

</div>

also it was just pointed out to me, the syncronize module already does  
what you ask.

---

<div class="post-metadata">

**Author:** ![Alexander\_Taler](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Alexander\_Taler](https://forum.ansible.com/u/Alexander_Taler)\
**Post date:** [August 5, 2015, 8:13pm UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/6 "2015-08-05T20:13:56Z")

</div>

> ah, misunderstood what you mean by local, there is a feature request for

&nbsp;&nbsp;\> adding this feature to the existing copy module

Yes, choosing a clear name is hard.

Are these the feature requests you were referring to?

&nbsp;&nbsp;[https://github.com/ansible/ansible/issues/9982](https://github.com/ansible/ansible/issues/9982)  
&nbsp;&nbsp;[https://github.com/ansible/ansible-modules-core/issues/365](https://github.com/ansible/ansible-modules-core/issues/365)

Would this be welcomed by the Ansible community? I see there are  
no comments on the request.

Would it be better provided as separate modules or just options  
on the existing copy module?

Also, looking at the synchronize module, the documentation  
suggests that it works local-\>remote or vice-versa, so has the  
same problems for me as the copy module that it would need to be  
run as a separate ansible on the remote host.

Alex

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel1](https://avatars.discourse-cdn.com/v4/letter/t/278dde/32.png) [@Timothy\_Appnel1](https://forum.ansible.com/u/Timothy_Appnel1)\
**Post date:** [August 5, 2015, 9:06pm UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/7 "2015-08-05T21:06:28Z")

</div>

```auto
Did you try this?:

```

```auto
# Synchronization of src on delegate host to dest on the current inventory host.
# If delegate_to is set to the current inventory host, this can be used to syncronize
# two directories on that host.

```

---

<div class="post-metadata">

**Author:** ![Alexander\_Taler](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Alexander\_Taler](https://forum.ansible.com/u/Alexander_Taler)\
**Post date:** [August 14, 2015, 5:45am UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/8 "2015-08-14T05:45:51Z")

</div>

Hi Timothy,

Thanks for the suggestion. I have given this a try. (After  
dealing with an rsync/SSH authentication issue - I've submitted a  
pull request.) I confirm that it does the trick and conveniently  
doesn't require authentication.

However, it doesn't support the additional selinux or similar  
features of the copy module.

I'd like to come back to my question, would a module which copies  
files locally on the remote host be welcome? It could support the  
SELinux settings and similar.

Here's another user with a similar request from just a few days  
ago:

[https://github.com/ansible/ansible-modules-core/pull/1894](https://github.com/ansible/ansible-modules-core/pull/1894)

Alex

---

<div class="post-metadata">

**Author:** ![Alexander\_Taler](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Alexander\_Taler](https://forum.ansible.com/u/Alexander_Taler)\
**Post date:** [August 16, 2015, 1:01am UTC](https://forum.ansible.com/t/new-module-draft-for-copying-files-locally/18940/9 "2015-08-16T01:01:34Z")

</div>

> I'd like to come back to my question, would a module which copies files

&nbsp;&nbsp;\> locally on the remote host be welcome? It could support the SELinux  
&nbsp;&nbsp;\> settings and similar.

I've updated my code to support the standard file attributes  
(mode, owner, group, SELinux), by using the existing module  
functions.

[https://gist.github.com/alex-deref/dc66a0ca7e1904c30508](https://gist.github.com/alex-deref/dc66a0ca7e1904c30508)

Alex
