syncthing_device: Accept path to the configuration file

Specifying `config_file` overrides the default path relative to
the current user.

This is handy when the executing user is a different user.
This commit is contained in:
Borjan Tchakaloff 2021-01-01 16:01:13 +01:00
parent e336ebde13
commit 11282b098e

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright: (c) 2018, Rafael Bodill <justrafi at google mail> # 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) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = { ANSIBLE_METADATA = {
@ -39,6 +40,12 @@ options:
- API key to use for authentication with host. - API key to use for authentication with host.
If not provided, will try to auto-configure from filesystem. If not provided, will try to auto-configure from filesystem.
required: false 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: timeout:
description: description:
- The socket level timeout in seconds - The socket level timeout in seconds
@ -91,6 +98,9 @@ def make_headers(host, api_key):
def get_key_from_filesystem(module): def get_key_from_filesystem(module):
try: try:
if module.params['config_file']:
stconfigfile = module.params['config_file']
else:
stconfigfile = os.path.expandvars(DEFAULT_ST_CONFIG_LOCATION) stconfigfile = os.path.expandvars(DEFAULT_ST_CONFIG_LOCATION)
stconfig = parse(stconfigfile) stconfig = parse(stconfigfile)
root = stconfig.getroot() root = stconfig.getroot()
@ -166,6 +176,7 @@ def run_module():
name=dict(type='str', required=False), name=dict(type='str', required=False),
host=dict(type='str', default='http://127.0.0.1:8384'), host=dict(type='str', default='http://127.0.0.1:8384'),
api_key=dict(type='str', required=False, no_log=True), api_key=dict(type='str', required=False, no_log=True),
config_file=dict(type='str', required=False),
timeout=dict(type='int', default=30), timeout=dict(type='int', default=30),
state=dict(type='str', default='present', state=dict(type='str', default='present',
choices=['absent', 'present', 'pause']), choices=['absent', 'present', 'pause']),