# copying a file on a remote machine to the same remote machine

**URL:** <https://forum.ansible.com/t/copying-a-file-on-a-remote-machine-to-the-same-remote-machine/17146>\
**Category:** Ansible Project\
**Created:** [December 26, 2014, 5:50pm UTC](https://forum.ansible.com/t/copying-a-file-on-a-remote-machine-to-the-same-remote-machine/17146 "2014-12-26T17:50:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rambius](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rambius](https://forum.ansible.com/u/rambius)\
**Post date:** [December 26, 2014, 5:50pm UTC](https://forum.ansible.com/t/copying-a-file-on-a-remote-machine-to-the-same-remote-machine/17146/1 "2014-12-26T17:50:44Z")

</div>

Hello,

I want to copy a file that resides on a remote machine to the same remote machine. I am doing that right now with a shell command

shell: “cp {{backup\_utils\_dir}}/backup.config-example {{backup\_utils\_dir}}/backup.config”

Ansible has a copy module that copies files from the local box to the remote ones and a fetch module that copies files from remote machines to the local one. Is there a core module that copies from a remote to the same remote without reverting to shell commands?

Thank you in advance.

Regards  
Rambius

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [December 27, 2014, 8:21am UTC](https://forum.ansible.com/t/copying-a-file-on-a-remote-machine-to-the-same-remote-machine/17146/2 "2014-12-27T08:21:06Z")

</div>

Hi Rambius,

The Copy module takes a file from the local (control) machine and sends it to a target. The Fetch module takes a file from the target and pull it to the local machine.  
Using the modules in combination will ‘delegate\_to’ will not help you either, since that will perform the action against the delegated target instead.

In your scenario I would use the ‘command’ module though in conjunction with the ‘creates’ option like:

command: creates={{ backup\_utils\_dir }}/backup.config cp {{ backup\_utils\_dir }}/backup.config-example {{ backup\_utils\_dir }}/backup.config

Regards,  
Nico

---

<div class="post-metadata">

**Author:** ![rambius](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@rambius](https://forum.ansible.com/u/rambius)\
**Post date:** [December 29, 2014, 7:17pm UTC](https://forum.ansible.com/t/copying-a-file-on-a-remote-machine-to-the-same-remote-machine/17146/3 "2014-12-29T19:17:15Z")

</div>

Hello,

Thank you for your response.

27 декември 2014, събота, 03:21:06 UTC-5, Nico K. написа:

> Hi Rambius,
> 
> The Copy module takes a file from the local (control) machine and sends it to a target. The Fetch module takes a file from the target and pull it to the local machine.  
> Using the modules in combination will ‘delegate\_to’ will not help you either, since that will perform the action against the delegated target instead.
> 
> In your scenario I would use the ‘command’ module though in conjunction with the ‘creates’ option like:
> 
> command: creates={{ backup\_utils\_dir }}/backup.config cp {{ backup\_utils\_dir }}/backup.config-example {{ backup\_utils\_dir }}/backup.config

Yes, it looks like only command or shell modules will do it.

Regards  
Rambius

---

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [December 30, 2014, 8:33pm UTC](https://forum.ansible.com/t/copying-a-file-on-a-remote-machine-to-the-same-remote-machine/17146/4 "2014-12-30T20:33:54Z")

</div>

I think I did a feature request for this. A ‘command’ or ‘shell’ works just fine if you just want to copy, but if you want to set ownership / permissions / SELinix context / etc. then it starts to get messy, and a module would be a nice solution.
