How to fetch files from remote server to a controller

George Shuklin
OpsOps
Published in
1 min readJan 18, 2023

Forgot ‘fetch’, or ‘slurp’. Both are terrible to use. With big efforts I realized that synchronize CAN synchronize remote directory INTO local (on the controller).

The magic is around ‘mode’ parameter for synchronize :

mode string

Specify the direction of the synchronization.

In push mode the localhost or delegate is the source.

In pull mode the remote host in context is the source.

It’s the most convoluted description I ever saw.

This play synchronize content of the /var/lib/ispell/ from remote server foo into foo_sync/ directory (you need to create it beforehand) on the controller.

- hosts: foo
gather_facts: false
tasks:
- synchronize:
mode: pull
dest: foo_sync/
src: /var/lib/ispell/

Please pay attention to last ‘/’ in src.

If path is with ‘/’ at the end, it will sync files. If there is no ‘/’ at the end, it will sync ‘ispell’ directory (with content) in foo_sync.

Basically, with src: /var/lib/ispell/ :

$ find foo_sync/

foo_sync/
foo_sync/british.compat
foo_sync/british.hash
foo_sync/british.remove
foo_sync/README
foo_sync/american.compat
foo_sync/american.hash
foo_sync/american.remove

with src: /var/lib/ispell

$ find foo_sync/

foo_sync/
foo_sync/ispell
foo_sync/ispell/british.compat
foo_sync/ispell/british.hash
foo_sync/ispell/british.remove
foo_sync/ispell/README
foo_sync/ispell/american.compat
foo_sync/ispell/american.hash
foo_sync/ispell/american.remove

So simple to use, so hard to understand docs…

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.