From be5ee1d274ef8bb99f01b7111c2d5fa59364863a Mon Sep 17 00:00:00 2001 From: Swapnil Date: Wed, 15 May 2024 11:08:30 +0530 Subject: [PATCH] Added folders plugin --- collection/plugins/modules/folders.py | 89 +++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 collection/plugins/modules/folders.py diff --git a/collection/plugins/modules/folders.py b/collection/plugins/modules/folders.py new file mode 100644 index 0000000..a031c69 --- /dev/null +++ b/collection/plugins/modules/folders.py @@ -0,0 +1,89 @@ +#!/usr/bin/python +# -*- 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 = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community' +} + +DOCUMENTATION = ''' +--- +module: syncthing_folders + +short_description: Retrieve Syncthing folders + +version_added: "2.7" + +description: + - "This module retrieves the list of folders from Syncthing" + +options: + host: + description: + - Host to connect to, including port + default: http://127.0.0.1:8384 + unix_socket: + description: + - Use this unix socket instead of TCP + required: false + config_file: + description: + - Path to the Syncthing configuration file for automatic + discovery (`api_key`). Note that the running user needs read + access to the file. + required: false + timeout: + description: + - The socket level timeout in seconds + default: 30 + +author: + - Rafael Bodill (@rafi) +''' + +EXAMPLES = ''' +# Get folders +- name: Get folders + become: yes + become_user: syncthing + community.syncthing.folders: + host: http://localhost + unix_socket: /run/syncthing/syncthing.sock + config_file: /var/lib/syncthing/.config/syncthing/config.xml + register: folders +''' + +RETURN = ''' +folders: + description: The list of folders retrieved from Syncthing. + type: dict +response: + description: The API response, in-case of an error. + type: dict +''' + +from ansible_collections.community.syncthing.plugins.module_utils.syncthing_api import SyncthingModule + +def run_module(): + module = SyncthingModule( + api_url='/rest/config/folders', + ) + + folders = {} + folders_list = module.get_call() + for folder in folders_list: + folders[folder['id']] = folder + module.result['folders'] = folders + + module.exit_json() + +def main(): + run_module() + +if __name__ == '__main__': + main() -- 2.45.1