CertGrid CertGrid
Hands-on Lab·Ansible

Ansible File Copy and Fetch

Four modules move files and the only hard part is remembering which way each one goes. `copy`, `template` and `unarchive` push from the control node; `fetch` pulls to it. This runs a full round trip - create on one host, collect centrally, deploy to another - which is the shape of every log-collection and backup playbook.

Templates, Files and Vault Guide 20 of 45 Intermediate

Written against the versions above. `fetch` writes to `<dest>/<hostname>/<full source path>` by default, so files from different hosts cannot collide. `flat: true` drops the nesting and writes straight into `dest` - convenient for one host and dangerous for several, since they will overwrite each other.

Both managed nodes: files are created on the `web` host, collected to the control node, and unpacked on the `db` host.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-A01192.168.0.37Ubuntu 26.04 LTSManaged Node (group: web)2 Core3 GB50 GB
ANS-B01192.168.0.38Ubuntu 26.04 LTSManaged Node (group: db)2 Core3 GB50 GB

Before you start

  1. The configuration this guide assumes

  2. Something to package

  3. Archive on the managed node

  4. fetch pulls it back to the control node

  5. unarchive goes the other way

  6. Which way does each module go

Official sources