AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible synchronize Module: Rsync Files & Directories Between Hosts — Video Tutorial

Discover how to use Ansible synchronize module for efficient file backups with rsync. Learn practical steps and see real-world examples for Linux systems.

Watch Video

Watch "Ansible synchronize Module: Rsync Files & Directories Between Hosts" on YouTube

What You'll Learn

Full Tutorial Content

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 directory tree in a Linux machine using the rsync utility via syncronize module. code ```yaml --- - name: synchronize module Playbook hosts: all become: false vars: source: '~/prj/github/ansible-pilot/copy\ files\ to\ remote\ hosts/examples' destination: 'example-backup' tasks: - name: rsync installed ansible.builtin.package: name: rsync state: present become: true - name: data synchronization ansible.posix.synchronize: src: '{{ source }}'

About This Tutorial

Read the full written article: Ansible synchronize Module: Rsync Files & Directories Between Hosts

Topics Covered

Related Video Tutorials