Add 'devices'
- will return a dict of devices in format id: name
This commit is contained in:
parent
2c26c3a53e
commit
e61ad55945
103
collection/plugins/modules/devices.py
Normal file
103
collection/plugins/modules/devices.py
Normal file
|
@ -0,0 +1,103 @@
|
|||
#!/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_device
|
||||
|
||||
short_description: Manage Syncthing devices
|
||||
|
||||
version_added: "2.7"
|
||||
|
||||
description:
|
||||
- "This is my longer description explaining my sample module"
|
||||
|
||||
options:
|
||||
id:
|
||||
description:
|
||||
- This is the unique id of this new device
|
||||
required: true
|
||||
name:
|
||||
description:
|
||||
- The name for this new device
|
||||
required: false
|
||||
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
|
||||
api_key:
|
||||
description:
|
||||
- API key to use for authentication with host.
|
||||
If not provided, will try to auto-configure from filesystem.
|
||||
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
|
||||
state:
|
||||
description:
|
||||
- Use present/absent to ensure device is added, or not.
|
||||
default: present
|
||||
choices: ['absent', 'present', 'paused']
|
||||
|
||||
author:
|
||||
- Rafael Bodill (@rafi)
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Add a device to share with
|
||||
- name: Add syncthing device
|
||||
syncthing_device:
|
||||
id: 1234-1234-1234-1234
|
||||
name: my-server-name
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
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/devices',
|
||||
)
|
||||
|
||||
devices = {}
|
||||
devices_dict = module.get_call()
|
||||
own_id = module.result['response']['x-syncthing-id']
|
||||
for device in devices_dict:
|
||||
if device['deviceID'] == own_id:
|
||||
continue
|
||||
devices[device['deviceID']] = device['name']
|
||||
module.result['devices'] = devices
|
||||
|
||||
module.exit_json()
|
||||
|
||||
def main():
|
||||
run_module()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user