Interview Prep/Ansible/Ad-hoc Commands, Modules and Idempotency

What is the difference between `copy`, `synchronize` and `fetch`?

IntermediateConceptAd-hoc Commands, Modules and Idempotency
Answer

copy sends files from the control node to the target (or copies on the target with remote_src: true), and is fine for small files. synchronize wraps rsync (from ansible.posix) for large trees and deltas, and requires rsync on both ends. fetch goes the other way: it pulls files from targets to the control node.

- ansible.posix.synchronize:
    src: build/
    dest: /var/www/app/
    delete: true
- ansible.builtin.fetch:
    src: /var/log/app.log
    dest: logs/

fetch stores files under dest/<hostname>/path by default so hosts do not overwrite each other.

All Ansible questions Roadmap: Ansible

More on Ad-hoc Commands, Modules and Idempotency