LOGBOOK

HELP

Quiz Entry - updated: 2026.10.30

What does the fetch module do, and where does a fetched file end up?

fetch is the reverse of copy: it pulls a file from the managed host to the control node. By default it saves it under dest/<hostname>/<full remote path>, so files from many hosts don't overwrite each other.

- name: Transfer the access.log file
  ansible.builtin.fetch:
    src: /var/log/apache2/access.log
    dest: /tmp/access.log

fetch copies /var/log/apache2/access.log from each web host into a per-host subtree under dest on the control node

* fetch builds one subtree per host, so logs from many servers never collide. *

The surprise is the path. With dest: /tmp/access.log, the result is not a file /tmp/access.log but:

/tmp/access.log/debian-001.example/var/log/apache2/access.log

Ansible treats dest as a directory, adds the inventory hostname, then the full source path. That is deliberate: run against 20 web servers, you get 20 separate logs instead of one file overwritten 19 times. If you fetch from a single host and want an exact file name, set flat: yes (or end dest with / to keep only the basename).

Typical uses: collecting logs, configs or reports from many hosts for review on one machine.

Go deeper:

From Quiz: ITIA / Ansible Inventory, Configuration and Playbooks | Updated: Oct 30, 2026