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
- OSUbuntu 26.04 LTS
- ansible-core2.20.1
- Python3.14.4
- TimeAbout 15 min
- Reviewed23 August 2026
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.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| ANS-CTL01 | 192.168.0.36 | Ubuntu 26.04 LTS | Ansible Control Node | 2 Core | 3 GB | 50 GB |
| ANS-A01 | 192.168.0.37 | Ubuntu 26.04 LTS | Managed Node (group: web) | 2 Core | 3 GB | 50 GB |
| ANS-B01 | 192.168.0.38 | Ubuntu 26.04 LTS | Managed Node (group: db) | 2 Core | 3 GB | 50 GB |
Before you start
- A control node configured as shown in the first step.
- The session creates
/opt/appdataon thewebhost, a tarball in/tmp, a~/collected/tree on the control node, and unpacks onto thedbhost. All are removed at the end.
-
The configuration this guide assumes
-
Something to package
-
Archive on the managed node
-
fetch pulls it back to the control node
-
unarchive goes the other way
-
Which way does each module go