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

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

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

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

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.