Backup With Rsync — Local to Remote — Ansible module synchronize

How to automate the backup of an “examples” directory minimizing network usage on Linux using Ansible module synchronize and rsync utility.

Ansible Pilot
7 min readMar 28, 2022

--

How to backing up with rsync with Ansible?
I’m going to show you a live demo and some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

Ansible backup with rsync

  • `ansible.posix.synchronize`
  • `synchronize` is a wrapper around rsync to make common tasks in your playbooks quick and easy.

Today we’re talking about the Ansible module `synchronize`.

The full name is `ansible.posix.synchronize`, which means that is part of the collection targeting POSIX platforms.

A wrapper around `rsync` to make common tasks in your playbooks quick and easy.

rsync is a utility for efficiently transferring and synchronizing files between a computer and a storage drive and across networked computers by comparing the modification times and sizes of files.

rsync must be installed on both the local and remote host.

Currently, there are only a few connection types that support synchronize (ssh, paramiko, local, and docker) because a sync strategy has been determined for those connection types.

Main Parameters

  • src string — source path — absolute or relative
  • dest string — destination path — absolute or relative
  • archive boolean — mirrors the Rsync archive flag, enables recursive, links, perms, times, owner, group flags, and -D
  • rsync_opts string — no/yes

The parameter list is pretty wide but these are the most important options of `synchronize` module.

The only mandatory parameters are “src” and “dest” parameters.

--

--

Ansible Pilot

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday