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

73 views
Skip to first unread message

rambius

unread,
Dec 26, 2014, 12:50:44 PM12/26/14
to ansible...@googlegroups.com
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

Nico K.

unread,
Dec 27, 2014, 3:21:06 AM12/27/14
to ansible...@googlegroups.com
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

rambius

unread,
Dec 29, 2014, 2:17:16 PM12/29/14
to ansible...@googlegroups.com
Hello,

Thank you for your response.
Yes, it looks like only command or shell modules will do it.

Regards
Rambius

John Oliver

unread,
Dec 30, 2014, 3:33:54 PM12/30/14
to ansible...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages