hanru.lsyncd

Lsyncd Configurations

Overview

This Ansible role sets up file synchronization from a master host to one or more slave hosts. The Lsyncd daemon on the master takes care of the syncing. There is only one master, but multiple slaves can exist, and there can also be many sources (on the master) and targets (on the slaves) to synchronize.

On the master, the Lsyncd daemon runs as root. On the slaves, a special lsyncd user is created. This user can run sudo rsync, which helps keep file permissions intact. During synchronization, the master connects to the slaves using ssh as the lsyncd user and runs the rsync command.

Since Lsyncd runs in the background, a passwordless SSH key pair is created for the root user on the master. The public key is then copied to each slave.

On the master, the Lsyncd status file is at /var/lib/lsyncd/status, and the log file is at /var/log/lsyncd.log. Check these files regularly for any issues.

This role has been tested successfully on Debian Jessie (8.x), Debian Stretch (9.x), Ubuntu Trusty (14.04), and Ubuntu Xenial (16.04).

Role Variables

  • lsyncd_inotify_max_watches: 65536
    This is the maximum number of directories Lsyncd can watch. The default is 8192 on Debian. You may need to increase this if you are monitoring many files.

  • lsyncd_master_hostname:
    The hostname of the master. This should be one inventory_hostname from the inventory. Only one master is allowed.

  • lsyncd_master_identity_file: /root/.ssh/id_rsa_lsyncd
    This is the filename of the SSH private key for the root user on the master. A new key pair will be created if this file doesn’t exist.

  • lsyncd_slave_hosts: []
    A list of fully qualified domain names (FQDN) or IP addresses of slave hosts. You can have multiple slaves.

  • lsyncd_slave_username: lsyncd
    The username used on the slaves for the master to log in via SSH.

  • lsyncd_sources_and_targets: []
    A list of sources on the master that will sync with targets on the slaves. You can have multiple source-target pairs.

  • lsyncd_settings_status_interval: 10

  • lsyncd_sync_delay: 15
    These are tuning parameters for Lsyncd. Do not change them unless you are sure about it.

Dependencies

This role does not have any dependencies.

Example Playbook

Prepare an inventory. Here is an example inventory.

[lsyncd]
test1       ansible_host=10.0.0.1       ansible_user=root
test2       ansible_host=10.0.0.2       ansible_user=root
test3       ansible_host=10.0.0.3       ansible_user=root

In this example, the Ansible inventory_hostname variables are test1, test2, and test3. One must be the master host. We will use test1 as the master, and the other two will be the slaves.

Here’s an example playbook.

- hosts: lsyncd
  vars:
    lsyncd_master_hostname: test1
    lsyncd_slave_hosts:
      - 10.0.0.2
      - 10.0.0.3
    lsyncd_sources_and_targets:
      - source: /var/www
        target: /var/www
      - source: /home
        target: /backup/home
  roles:
    - { role: hanru.lsyncd }

License

MIT

References

Informazioni sul progetto

Lsyncd Configurations

Installa
ansible-galaxy install hanru.lsyncd
Licenza
mit
Download
1.5k
Proprietario