I’m kinda newbie with Ansible. I have a hosts file that contains 4 hosts.
I also have a ‘copymap’ dictionary that I built in order to copy data (folders) between the servers (the full ‘copymap’ dictionary is much bigger than the example below).
I would like to copy the data between the servers, when the source is copymap.src and the destination is copymap.dest.
I know how to iterate using ‘with_items’, but I’m not sure I understand how I can specify source and destination servers. Did anyone used the built-in ‘copy’ module to copy from dynamic remote to remote servers?
With one exception, ansible is all communication between the controller (where you run the ansible-playbook command) and the managed machines. So using copy you’d need to first fetch the remote files to the controller and then copy them out to the other machines.
The one exception is the synchronize module. Using delegate_to you can copy between two remote machines provided that you can live with certain limitations (ssh key authentication where at least one of the remote machines can ssh to the other one [I use ssh agent forwarding if I have to do this]. Very primitive privilege escalation which lacks many of the features you’re used to (password less sudo works). A summary of synchronize might read, operates in a different way than other modules which is sometimes exactly what you need but also an endless supply of bugs and missing features.
If synchronize doesn’t satisfy your use case, using ansible to set up rsync between your servers and using ansible or Cron to start the rsync job might be a way to go.