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
Related
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.
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.
I am trying to copy a file (example: /home/abc.jar) from controller machine(source system) to remote server. but before copying that file, I want to take the backup of the already existed file (/home/abc.jar) on the remote server to some directory (example /home/bck/abc.jar). then copy the new file ,
How can I write the playbook for this using ansible?
Thank you :)
The docs are your friend:
Ansible Copy Module
Ansible Template Module
Both contain a 'backup' parameter which will automatically take a backup of a file prior to making changes.
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
In my RF scripts, I need to modify the hosts file under c:\windows\system32\drivers\etc to finish my test job. But the scripts fail with ERROR 20047, I tried to create file in another folder, it was OK. I get the conclusion that it only doesn't work in folder etc, it seems that I do have the permission to create/modify hosts file. I modified the owner of folder etc and granted all permission to the current user and tried again. It still does not work.
BTW: The RF scripts run with jython. I find that It works while I use python to create/modify hosts in folder etc.
Could anyone help me ?