How to backing up with rsync with Ansible?
I'm going to show you a live Playbook 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.
The "src" parameter is mandatory and specifies the path on the source host that will be synchronized to the destination. The path can be absolute or relative.
Same story for the dest parameter that specifies the path on the destination host that will be synchronized from the source.
Paths could be Local or Remote according to your needs.
The most useful parameter is "archive", which mirrors the Rsync archive flag, enables recursive, links, perms, times, owner, group flags, and -D. It's enabled by default so in the majority of use-cases you don't need to specify anything else. Please refer to the manual to enable/disable some specific settings.
It's possible to specify more Rsync parameters via the "rsync_opts" parameter.
Links
- [rsync](https://en.wikipedia.org/wiki/Rsync)
- [ansible.posix.synchronize](https://docs.ansible.com/ansible/latest/collections/ansible/posix/synchronize_module.html)
## Playbook
How to backup with rsync with Ansible Playbook.
I’m going to show you how to replicate some d