LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

What does ansible.builtin.copy do when the destination file already exists, and what does force: false change?

By default (force: true) it overwrites the remote file if its content differs, and leaves it alone if it is identical; with force: false it copies only if the file doesn't exist yet and never touches an existing one.

- name: Copy a file to managed hosts
  ansible.builtin.copy:
    src: file
    dest: /path/to/file

src is relative to the playbook's files/ directory (or the playbook directory), on the control node; dest is the path on the managed host.

copy compares checksums before transferring. Same content: ok, nothing sent. Different content: the file is replaced and the task reports changed, which is what makes copy idempotent and handler-friendly.

force: false turns it into "create once": useful for a config file that ships with sensible defaults and is then maintained on the host by someone else. Ansible won't overwrite their edits, but it also won't push your updates. Pick it deliberately; most configuration should stay under Ansible's control (force: true).

Go deeper:

From Quiz: ITIA / Ansible: Managing Files and Jinja2 Templates | Updated: Nov 12, 2026