From 83e9add60cd43edff90b61a356c8c211daa0369f Mon Sep 17 00:00:00 2001 From: Borjan Tchakaloff Date: Fri, 1 Jan 2021 15:25:33 +0100 Subject: [PATCH] syncthing_folder: Always update the devices the folder is shared with Ensure all devices the folder should be shared with is part of the folder configuration. Previously, only at folder creation would the devices be set. --- README.md | 1 + library/storage/syncthing/syncthing_folder.py | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39de1ca..8f2312f 100644 --- a/README.md +++ b/README.md @@ -108,4 +108,5 @@ Examples: ## License Copyright: (c) 2018, Rafael Bodill `` +Copyright: (c) 2020, Borjan Tchakaloff `` GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) diff --git a/library/storage/syncthing/syncthing_folder.py b/library/storage/syncthing/syncthing_folder.py index 027734d..685ce45 100644 --- a/library/storage/syncthing/syncthing_folder.py +++ b/library/storage/syncthing/syncthing_folder.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # Copyright: (c) 2018, Rafael Bodill +# Copyright: (c) 2020, Borjan Tchakaloff # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = { @@ -242,8 +243,25 @@ def run_module(): for folder in config['folders']: if folder['id'] == module.params['id']: want_pause = module.params['state'] == 'pause' - if (want_pause and folder['paused']) or \ - (not want_pause and not folder['paused']): + already_configured = ( + (want_pause and folder['paused']) + or + (not want_pause and not folder['paused']) + ) + + want_devices = sorted([ + { + 'deviceID': device_id, + 'introducedBy': '', + } for device_id in module.params['devices'] + ], key=lambda d: d['deviceID']) + already_configured = ( + already_configured + and + want_devices == sorted(folder['devices'], key=lambda d: d['deviceID']) + ) + + if already_configured: module.exit_json(**result) else: folder['paused'] = want_pause