summaryrefslogtreecommitdiff
path: root/action_plugins
diff options
context:
space:
mode:
authorJulien Dessaux2023-01-23 17:33:53 +0100
committerJulien Dessaux2023-01-23 23:12:56 +0100
commitb6ee8f76c2883a934bcf412722e0cf83830173c9 (patch)
tree97d33cb1f4ea74e0b277a4ed6890b35bc022816e /action_plugins
parentImported from personal ansible repository (diff)
downloadsyncthing-ansible-role-b6ee8f76c2883a934bcf412722e0cf83830173c9.tar.gz
syncthing-ansible-role-b6ee8f76c2883a934bcf412722e0cf83830173c9.tar.bz2
syncthing-ansible-role-b6ee8f76c2883a934bcf412722e0cf83830173c9.zip
Simplify fact gathering by using the cli instead of a webapi request1.1
Diffstat (limited to 'action_plugins')
-rw-r--r--action_plugins/syncthing_init.py19
-rw-r--r--action_plugins/syncthing_pre.py46
2 files changed, 48 insertions, 17 deletions
diff --git a/action_plugins/syncthing_init.py b/action_plugins/syncthing_init.py
index eb6cf9f..58dc472 100644
--- a/action_plugins/syncthing_init.py
+++ b/action_plugins/syncthing_init.py
@@ -28,14 +28,14 @@ class ActionModule(ActionBase):
syncthing = hostvars['syncthing']
peer = {
'address': 'dynamic',
- 'id': '0000000-0000000-0000000-0000000-0000000-0000000-0000000-0000000',
+ 'id': '',
'shared': [],
}
if 'address' in syncthing.keys():
peer['address'] = syncthing['address']
for shared in syncthing['shared']:
peer['shared'].append({ 'name': shared['name'], 'path': shared['path'], 'peers': shared['peers']})
- if 'syncthing' in hostvars['ansible_local']:
+ if 'ansible_local' in hostvars and 'syncthing' in hostvars['ansible_local']:
peer['id'] = hostvars['ansible_local']['syncthing']['id']
peers[hostname] = peer
@@ -44,24 +44,9 @@ class ActionModule(ActionBase):
if task_vars['ansible_host'] in peers.keys():
myself = peers[task_vars['ansible_host']]
config = {
- 'config_path': "",
- 'folders_to_create': [],
- 'packages': [],
'peers': {},
- 'service': "syncthing",
'shared': myself['shared'],
- 'user_group': "syncthing",
}
- if task_vars['ansible_distribution'] == 'FreeBSD':
- config['config_path'] = "/usr/local/etc/syncthing/config.xml"
- config['folders_to_create'] = ["/usr/local/etc/syncthing/", "/var/syncthing"]
- config['packages'] = ["p5-libwww", "syncthing"]
- elif task_vars['ansible_distribution'] == 'Gentoo':
- config['config_path'] = "/var/lib/syncthing/.config/syncthing/config.xml"
- config['folders_to_create'] = ["/var/lib/syncthing/.config/syncthing"]
- config['packages'] = ["net-p2p/syncthing"]
- else:
- error_msgs.append(f"syncthing role does not support {task_vars['ansible_distribution']} hosts yet")
for shared in myself['shared']:
for peer in shared['peers']:
if not peer in config['peers'].keys():
diff --git a/action_plugins/syncthing_pre.py b/action_plugins/syncthing_pre.py
new file mode 100644
index 0000000..4b7b0b3
--- /dev/null
+++ b/action_plugins/syncthing_pre.py
@@ -0,0 +1,46 @@
+from ansible.plugins.action import ActionBase
+import re
+import yaml
+from yaml.loader import SafeLoader
+
+class ActionModule(ActionBase):
+ def run(self, tmp=None, task_vars=None):
+ if task_vars is None:
+ task_vars = dict()
+ result = super(ActionModule, self).run(tmp, task_vars)
+ result['changed'] = False
+ result['failed'] = False
+
+ error_msgs = []
+
+ ### Compiling host configuration ######################################
+ config = {}
+ if 'syncthing' in task_vars:
+ config = {
+ 'config_path': "",
+ 'folders_to_create': [],
+ 'packages': [],
+ 'service': "syncthing",
+ 'user_group': "syncthing",
+ }
+ if task_vars['ansible_distribution'] == 'FreeBSD':
+ config['config_dir'] = "/usr/local/etc/syncthing/"
+ config['data_dir'] = "/var/syncthing"
+ config['packages'] = ["syncthing"]
+ elif task_vars['ansible_distribution'] == 'Gentoo':
+ config['config_dir'] = "/var/lib/syncthing/.config/syncthing/"
+ config['data_dir'] = "/var/lib/syncthing"
+ config['packages'] = ["net-p2p/syncthing"]
+ else:
+ error_msgs.append(f"syncthing role does not support {task_vars['ansible_distribution']} hosts yet")
+
+ ### Results compilation ##############################################
+ if error_msgs != []:
+ result['msg'] = ' ; '.join(error_msgs)
+ result['failed'] = True
+
+ result['ansible_facts'] = {
+ 'syncthing_pre': config,
+ }
+
+ return result