90 lines
2.1 KiB
Python
90 lines
2.1 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright: (c) 2018, Rafael Bodill <justrafi at google mail>
|
|
# Copyright: (c) 2020, Borjan Tchakaloff <first name at last name dot fr>
|
|
# 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()
|