What are the pros and cons to using Ansible Synchronize vs Copy modules. As far as I can tell synchronize has all the functionality that copy does but may be much faster so I'm considering changing everything to use synchronize. The only downside of synchronize is that rsync is required, which seems fairly ubiquitous in the Linux environment.
4 Answers
The differences are pretty similar to traditional rsync
vs scp
. Rsync has more features and is often faster, however it's a little bit trickier to setup and has more knobs to turn.
Additionally, https://docs.ansible.com/ansible/copy_module.html states:
The “copy” module recursively copy facility does not scale to lots (>hundreds) of files. For alternative, see synchronize module, which is a wrapper around rsync.

- 8,979
- 4
- 27
- 37
As of Ansible v2.8, synchronize
is still in “preview” status:
This module is not guaranteed to have a backwards compatible interface. [preview]
In Ansible v2.10, the copy
module is moved to the Builtin Collection, which is officially maintained by the core team (i.e. Red Hat), and distributed with ansible-base
(a.k.a. ansible-core
). In contrast, synchronize
is moved to the POSIX Collection maintained by community.
I would use copy
when I don’t need the performance and functionality of synchronize
. I suggest starting with copy
, and move to synchronize
only when this is the bottleneck. (Verify this with benchmark!)

- 8,920
- 6
- 43
- 57
There is one big difference that was a showstopper for us: synchronize
does not reuse the ssh
session from ansible. When using a load-balancer, this caused us quite a headache to find the root cause:
ansible
would start an ssh-session to a load-balancer, and would end up at machine1- all tasks would thus work wrt machine1
- the
synchronize
task usesrsync
under the hood which starts a newssh
session and might end up connecting to machine2 (randomly) - when other tasks depend on the files from the
synchronize
being present, they will fail because the files are present on another machine.

- 35,025
- 12
- 111
- 136
-
Thanks for the explanation. I also found the synchronize task to unpredictably fail on rare occasions and have avoided using it since. This is probably the underlying reason. – Alex Ethier Jul 15 '20 at 23:42
-
2I think your failing there is using a load balancer, not the synchronize module. If you're copying files, you should be explicitly specifying hostnames, not rolling dice with a load balancer. – Asa Stallard Dec 15 '22 at 23:45
Using ansible 2.4.2.0, this works flawlessly. I should probably not be using ansible from the CentOS repos. Too far behind the curve, no offense to CentOS.
- hosts: all
become: true
tasks:
- name: copy icinga2 2.7.2
synchronize:
src: /home/ansible/playbooks/files/icinga2.7
dest: /home/ansible
owner: yes