aboutsummaryrefslogtreecommitdiff
path: root/action_plugins/borg_init.py
diff options
context:
space:
mode:
authorJulien Dessaux2021-05-02 18:42:01 +0200
committerJulien Dessaux2021-05-02 18:42:01 +0200
commit5d9a22501476b3384451b98eeb6b1dee65fed21d (patch)
tree51bcbd1914beda62ea450fb14bba3ee13670e52a /action_plugins/borg_init.py
parentFixed stupid ansible python sucks silent name collision (diff)
downloadborg-ansible-role-5d9a22501476b3384451b98eeb6b1dee65fed21d.tar.gz
borg-ansible-role-5d9a22501476b3384451b98eeb6b1dee65fed21d.tar.bz2
borg-ansible-role-5d9a22501476b3384451b98eeb6b1dee65fed21d.zip
Reworked and improved borg role
Diffstat (limited to 'action_plugins/borg_init.py')
-rw-r--r--action_plugins/borg_init.py37
1 files changed, 33 insertions, 4 deletions
diff --git a/action_plugins/borg_init.py b/action_plugins/borg_init.py
index 1775271..9dde218 100644
--- a/action_plugins/borg_init.py
+++ b/action_plugins/borg_init.py
@@ -9,17 +9,46 @@ class ActionModule(ActionBase):
result['changed'] = False
result['failed'] = False
- is_server = False
+ error_msgs = []
+ ### OS support #######################################################
+ os_package_names = {
+ 'Alpine': 'borgbackup',
+ 'Debian': 'borgbackup',
+ 'Gentoo': 'app-backup/borgbackup',
+ 'OpenBSD': 'borgbackup',
+ 'RedHat': 'borgbackup',
+ }
+ if task_vars['ansible_os_family'] not in os_package_names:
+ error_msgs.append(f"borg role does not support {task_vars['ansible_os_family']} os family clients yet")
+
+ ### Borg server variables ############################################
+ server = {
+ 'clients': [], # a list of hostnames
+ }
for hostname, hostvars in task_vars['hostvars'].items() :
if 'borg_server' in hostvars.keys() and hostvars['borg_server'] == task_vars['ansible_host']:
- is_server = True
+ server['clients'].append(hostname)
+
+ ### Borg client variables ############################################
+ client = {
+ 'server': '', # a server hostname
+ }
+ if 'borg_server' in task_vars:
+ client['server'] = task_vars['borg_server']
+
+ ### Results compilation ##############################################
+ if error_msgs != []:
+ result['msg'] = ' ; '.join(error_msgs)
+ result['failed'] = True
+ return result
result['ansible_facts'] = {
'borg': {
- 'is_server': is_server,
+ 'client': client,
+ 'package_name': os_package_names[task_vars['ansible_os_family']],
+ 'server': server,
}
}
return result
-