how to copy directories from remote machines to localhost? - ansible

In ansible playbook, fetch module only copies file from target machine to local.
copy/synchronize modules can copy directories/files from local to target machine.
Then how to copy direcotries from remote target machines

Acording to ducumentation :
synchronize – A wrapper around rsync
mode(string) Choices: {pull,push}
Specify the direction of the synchronization.
In push mode the localhost or delegate is the source.
In pull mode the remote host in context is the source.

This is not specific to ansible but you can use scp:
scp me#my-host /path/to/remote/folder /path/to/local/folder
This will copy the folder from your remote machine to a local folder.

Related

Ansible Copy directory from remote server to another remote host

I need to copy directory from one remote host(which is not in inventory file/hosts file) to actually my working server(which is in inventory file). I can`t actually add the host from which I am copying to inventory file, cause I have a lot of tasks on the working host. I just need to to something like ssh to needed server, copy directory and paste it to working server. How can I deal with it? Cause fetch is copying only files as I can see and also it's working with hosts file/inventory file. But I need actually something like paste IP -> connect to it -> copy directory
P.S.
Working server(host) - the host from inventory file, on which ansible playbook is running
Remote host - another VM, from which I need copy directory

How to copy folder from local to remote and delete if the local is missing?

I'm looking for a way to copy a folder from local to remote, and delete it on the remote if it doesn't exist on the local machine.
It seems that there is no such option in the 'copy' module.
Thanks

How to transfer the files between remotes machines with ansible

With Ansible, I want to transfer a file from windows environment remote to linux environment remote without going through the controller machine.

Copy files from local directory to docker container on a remote host

I want to create a watcher that will automatically sync file changes from a local directory to a remote docker container. I need to find a way to transfer the files efficiently. I will also need it for a one time upload command which would transfer a complete folder from local directory to a remote docker container.
I figure one solution would be to scp to a tmp directory on the remote host, and then run docker cp via ssh to copy the files from tmp directory. Is that a good solution? Is there anything better?
By the way, if anyone knows a file sync utility for that use case, please let me know. I tried to search, but it seems like it's not the most popular development workflow?
I would tr using rsync for local to remote host syncing. From their volume mount the directory into the docker container.

Modify source file used for the Copy on the target machine

I'm using the Copy module to transfer a 10G file from my machine to the remote /tmp dir. However, Copy uses an intermediate folder inside home and I need to transfer the file directly to /tmp because /home doesn't have enough space.
Is it possible to control the src path used by the Copy module?
Thanks
In your ansible.cfg change the "remote_tmp" to a location where sufficient space available or you run your playbook as below:
ANSIBLE_REMOTE_TEMP=/dir1/some_dir/large_space/ ansible-playbook copy.yml
Official Documentation for ANSIBLE_REMOTE_TEMP with shell plugin

Resources