Which extra file modules come from the ansible.posix collection, and when do you reach for synchronize instead of copy?
ansible.posix.patch applies patches with GNU patch, and ansible.posix.synchronize wraps rsync. Use synchronize for many files or whole directory trees, where rsync only transfers what changed.
ansible.posix is a separate collection (part of the Ansible package, not of bare ansible-core), so the full name ansible.posix.synchronize is required.
- name: synchronize local file to remote files
ansible.posix.synchronize:
src: file
dest: /path/to/file
How synchronize differs from copy:
copy |
synchronize |
|
|---|---|---|
| Engine | Ansible transfers each file | runs rsync |
| Needs on the hosts | Python only | rsync on both ends |
| Good for | single files, small sets | big trees, incremental updates, delete of extra files |
| Coverage | full Ansible attributes | the common rsync options, not all of them |
By default the "local host" is where the task runs, usually the control node, and the target is the managed host (mode: push). mode: pull turns the direction around. For rsync features the module doesn't expose, the docs suggest calling rsync with the command module.
Go deeper:
ansible.posix.synchronize module (official docs) —
mode,delete,rsync_optsand the delegation rules.rsync (Wikipedia) — the delta-transfer algorithm behind it.