GithubHelp home page GithubHelp logo

riiid / ansible_role_syncthing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from diademiemi/ansible_role_syncthing

0.0 1.0 0.0 110 KB

Ansible role to install and configure Syncthing with devices and folders

License: MIT License

Jinja 100.00%

ansible_role_syncthing's Introduction

Ansible Role Syncthing

Molecule Test

This is an Ansible role that installs Syncthing on Linux. It uses the tarball from the official website so this role is not dependent on any package manager.

This role can also optionally configure the devices and folders on the Syncthing instance.

Tested on Fedora 36, should work on any Linux distribution that the Syncthing tarball supports.

Requirements

These platforms are supported:

  • Ubuntu 20.04
  • Ubuntu 22.04
  • Debian 10
  • Debian 11
  • Debian 12
  • EL 8 (Tested on Rocky Linux 8)
  • EL 9 (Tested on Rocky Linux 9)
  • Fedora 38
  • openSUSE Leap 15.5

Role Variables

Variable Default Description
syncthing_version v1.23.4 Version of Syncthing to install.
syncthing_arch amd64 Architecture for the Syncthing package.
syncthing_url See defaults/main.yml Base URL for the Syncthing tarball.
syncthing_user {{ ansible_user_id }} User to configure Syncthing for.
syncthing_install_user true Whether to configure and enable syncthing to run as this user
syncthing_device_name {{ inventory_hostname }} Name of the Syncthing device to other devices.
syncthing_hosts {{ ansible_play_hosts_all }} List of hosts (including self) to use as Syncthing peers.
syncthing_configure true Whether to configure Syncthing.
syncthing_configure_firewall true Whether to configure firewall rules for Syncthing to work locally.
syncthing_bootstrap_only false Whether to only configure Syncthing once.
syncthing_gui_enabled true Whether to enable the Syncthing GUI.
syncthing_gui_address 127.0.0.1:8384 Address to bind the Syncthing GUI to.
syncthing_gui_apikey "" API key to use for the Syncthing GUI.
syncthing_gui_theme default Theme to use for the Syncthing GUI.

Configuration

This Ansible role will overwrite your Syncthing configuration, be careful!

This role by default will also overwrite any manual changes, if you want to just use this role to install and set up Syncthing one time, and do the rest manually, set syncthing_bootstrap_only to true.
Otherwise, every time this role is run, it will overwrite configuration that is not stored in the Ansible variables.

Devices

The syncthing_devices variable is used to configure remote devices on the Syncthing instance. This variable is not required, if this variable is not set, this role will generate it based on the other hosts in this play.
If you want to configure devices manually, you can set this variable yourself.

Static list of devices
syncthing_devices: # Static list of devices
  - name: "My Laptop"
    device_id: "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"
    address: dynamic
  - name: "My PC"
    device_id: "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"
    address: dynamic

A likely scenario is that you just want to add existing hosts not managed by this Ansible role (like your mobile phone) to this list, in which case you can use the variable syncthing_external_devices.

syncthing_external_devices: # Append to auto generated devices
  - name: "My Non-Ansible Managed Phone"
    device_id: "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"
    address: dynamic

Folders

The syncthing_folders variable is a dict of dicts. The key is the folder ID, and the value is a dict of folder configuration.

syncthing_folders:
  sync:
    label: Sync
    path: "/home/{{ syncthing_user }}/Sync"

The key is used as the folder ID in Syncthing, this must be the same on every device you want using this folder. When this key is set on multiple hosts this folder will be shared across these hosts.

If you defined hosts that are not in the Ansible play (with syncthing_external_devices or syncthing_devices), you will need to specify that this folder should be shared with those hosts by giving the ID in the list manual_shared_with.

Example for external devices
syncthing_folders:
  sync:
    label: Sync
    path: "/home/{{ syncthing_user }}/Sync"
    manual_shared_with: # Append to auto generated shared devices
      - "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"

The folder configuration can include label, path, type, rescanIntervalS, fsWatcherEnabled , fsWatcherDelayS, ignorePerms and autoNormalize. The label and path keys are required for each folder.

You can set the default configuration for all folders by setting the syncthing_folders_default variable. This will also be used in the UI as the defaults for management outside of Ansible.

Defaults
syncthing_folder_defaults: # Will be used if missing from folder
  path: "/home/{{ syncthing_user }}/Sync"
  type: sendreceive
  rescanIntervalS: "3600"
  fsWatcherEnabled: "true"
  fsWatcherDelayS: "10"
  ignorePerms: "false"
  autoNormalize: "true"

Example

The following is an example of a playbook that uses this role.

inventory.ini
[syncthing]
desktop
laptop
group_vars/syncthing.yml
syncthing_external_devices: # Append to auto generated devices
  - name: "My Non-Ansible Managed Phone"
    device_id: "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"
    address: dynamic

The device entries for desktop and laptop will be generated automatically based on the hosts in the play.

host_vars/desktop.yml
syncthing_folders:
  all:
    label: Shared with all
    path: /home/{{ syncthing_user }}/Sync
    manual_shared_with: # Append to auto generated shared devices
      - "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"
  phone:
    label: Shared with my phone
    path: /home/{{ syncthing_user }}/Phone
    manual_shared_with: # Append to auto generated shared devices
      - "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"
host_vars/laptop.yml
syncthing_folders:
  all:
    label: Shared with all
    path: /home/{{ syncthing_user }}/Sync
    manual_shared_with: # Append to auto generated shared devices
      - "AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH"

Since the phone key doesn't appear here, it won't be shared with this device.

playbook.yml
- hosts: syncthing
  roles:
    - ansible_role_syncthing

Dependencies

None

Example Playbook

- name: Use diademiemi.syncthing role
  hosts: "{{ target | default('syncthing') }}"
  roles:
    - role: "diademiemi.syncthing"
      tags: ['diademiemi', 'solaar', 'setup']

License

MIT

Author Information

  • diademiemi (@diademiemi)

Role Testing

This repository comes with Molecule that run in Podman on the supported platforms. Install Molecule by running

pip3 install -r requirements.txt

Run the tests with

molecule test

ansible_role_syncthing's People

Contributors

beleap avatar diademiemi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.