From b559ddb834896efb4e9e2761efc672d7f3fd59f1 Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Wed, 17 Jan 2024 10:37:45 +0100 Subject: [PATCH 01/11] feat(plugins): argument specs, replace yes to true --- meta/argument_specs.yml | 4 ++++ tasks/assert.yml | 33 ++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml index 8ab0944..fbd2fd2 100644 --- a/meta/argument_specs.yml +++ b/meta/argument_specs.yml @@ -65,3 +65,7 @@ argument_specs: type: "str" default: "" description: "The master public key to use." + bareos_fd_plugins: + type: "list" + default: [] + description: "Bareos plugins to install on the FD" diff --git a/tasks/assert.yml b/tasks/assert.yml index ca435f5..26dc665 100644 --- a/tasks/assert.yml +++ b/tasks/assert.yml @@ -5,7 +5,7 @@ that: - bareos_fd_backup_configurations is defined - bareos_fd_backup_configurations is boolean - quiet: yes + quiet: true - name: assert | Test bareos_fd_hostname ansible.builtin.assert: @@ -13,7 +13,7 @@ - bareos_fd_hostname is defined - bareos_fd_hostname is string - bareos_fd_hostname is not none - quiet: yes + quiet: true - name: assert | Test bareos_fd_max_job_bandwidth ansible.builtin.assert: @@ -21,7 +21,7 @@ - bareos_fd_max_job_bandwidth is defined - bareos_fd_max_job_bandwidth is string - bareos_fd_max_job_bandwidth is not none - quiet: yes + quiet: true - name: assert | Test bareos_fd_message ansible.builtin.assert: @@ -29,63 +29,63 @@ - bareos_fd_message is defined - bareos_fd_message is string - bareos_fd_message is not none - quiet: yes + quiet: true - name: assert | Test bareos_fd_tls_enable ansible.builtin.assert: that: - bareos_fd_tls_enable is defined - bareos_fd_tls_enable is boolean - quiet: yes + quiet: true - name: assert | Test bareos_fd_tls_verify_peer ansible.builtin.assert: that: - bareos_fd_tls_verify_peer is defined - bareos_fd_tls_verify_peer is boolean - quiet: yes + quiet: true - name: assert | Test bareos_fd_heartbeat_interval ansible.builtin.assert: that: - bareos_fd_heartbeat_interval is defined - bareos_fd_heartbeat_interval is number - quiet: yes + quiet: true - name: assert | Test bareos_fd_maximum_concurrent_jobs ansible.builtin.assert: that: - bareos_fd_maximum_concurrent_jobs is defined - bareos_fd_maximum_concurrent_jobs is number - quiet: yes + quiet: true - name: assert | Test bareos_fd_directors ansible.builtin.assert: that: - bareos_fd_directors is defined - bareos_fd_directors is iterable - quiet: yes + quiet: true - name: assert | Test bareos_fd_messages ansible.builtin.assert: that: - bareos_fd_messages is defined - bareos_fd_messages is iterable - quiet: yes + quiet: true - name: assert | Test bareos_fd_encryption_enabled ansible.builtin.assert: that: - bareos_fd_encryption_enabled is defined - bareos_fd_encryption_enabled is boolean - quiet: yes + quiet: true - name: assert | Test bareos_fd_encryption_private_key ansible.builtin.assert: that: - bareos_fd_encryption_private_key is defined - bareos_fd_encryption_private_key is string - quiet: yes + quiet: true when: - bareos_fd_encryption_enabled @@ -95,6 +95,13 @@ - bareos_fd_encryption_master_public_key is defined - bareos_fd_encryption_master_public_key is string - bareos_fd_encryption_master_public_key != "" - quiet: yes + quiet: true when: - bareos_fd_encryption_enabled + +- name: assert | Test bareos_fd_plugins + ansible.builtin.assert: + that: + - bareos_fd_plugins is defined + - bareos_fd_plugins is iterable + quiet: true From 0495fcca6c3bf24e173caf303abea629a57c190e Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Thu, 18 Jan 2024 13:21:18 +0100 Subject: [PATCH 02/11] chore(molecule): add bareos_fd_plugins to converge --- molecule/default/converge.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 9a69969..e16db6a 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -116,3 +116,4 @@ - "!saved" - name: "disabled-message" enabled: no + bareos_fd_plugins: [] From f87cd61d538dded9d4848e3f7e7bede658e8d506 Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 13:01:25 +0100 Subject: [PATCH 03/11] feat(plugins): import tasks plugins.yml in main.yml --- tasks/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index 3632bc3..020dce3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -65,6 +65,13 @@ when: - bareos_fd_encryption_enabled +- name: Import plugin tasklist + ansible.builtin.import_tasks: + file: plugins.yml + when: + - bareos_fd_plugins is defined + - bareos_fd_plugins is iterable + - name: Start bareos-filedaemon ansible.builtin.service: name: "{{ bareos_fd_service }}" From 5b19af51a7bbfb299941b8e708a0ad77467c413d Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 13:01:52 +0100 Subject: [PATCH 04/11] feat(plugin): task to install FD plugin packages --- tasks/plugins.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tasks/plugins.yml diff --git a/tasks/plugins.yml b/tasks/plugins.yml new file mode 100644 index 0000000..b32ee1f --- /dev/null +++ b/tasks/plugins.yml @@ -0,0 +1,12 @@ +--- + +- name: Get Bareos plugin package names + ansible.builtin.set_fact: + #_plugin_packages: "{{ bareos_fd_plugin_list[item.name].package_name }}" + _plugin_packages: "{{ bareos_fd_plugin_list | selectattr('name', 'match', item.name ) | map(attribute='package_name') }}" + loop: "{{ bareos_fd_plugins }}" + +- name: Install Bareos plugin packages + ansible.builtin.package: + name: "{{ _plugin_packages }}" + state: present From 32b467744b81597eb806cfa7b03935d0189cd795 Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 13:02:45 +0100 Subject: [PATCH 05/11] feat(plugins): add plugin list to vars, update myself.conf template --- templates/myself.conf.j2 | 17 +++++++++++++++++ vars/main.yml | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/templates/myself.conf.j2 b/templates/myself.conf.j2 index 2637dc3..3804c5c 100644 --- a/templates/myself.conf.j2 +++ b/templates/myself.conf.j2 @@ -22,4 +22,21 @@ Client { PKI Master Key = "/etc/bareos/master.pub.key" PKI Cipher = aes128 {% endif %} + +{# + bareos_fd_plugins is defined on host/group level, + while bareos_fd_plugin_list is a role var, with all available plugins +#} +{% if bareos_fd_plugins is defined %} +{% for plugin in bareos_fd_plugins %} +{% for item in bareos_fd_plugin_list if item.name == plugin %} + {% if item.plugin_dir is defined %} + Plugin Directory = "{{ item.plugin_dir }}" + {% endif %} + {% if item.plugin_names is defined %} + Plugin Names = "{{ item.plugin_names }}" + {% endif %} +{% endfor %} +{% endfor %} +{% endif %} } diff --git a/vars/main.yml b/vars/main.yml index 32f07ee..3c55bb4 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -31,3 +31,19 @@ _bareos_fd_debug_packages: - bareos-debuginfo - gdb bareos_fd_debug_packages: "{{ _bareos_fd_debug_packages[ansible_os_family ~ '-' ~ ansible_distribution_major_version] | default(_bareos_fd_debug_packages[ansible_os_family]) | default(_bareos_fd_debug_packages['default']) }}" + +# A list of Bareos FD plugins and their packages +bareos_fd_plugin_list: + - name: mariabackup + package_name: bareos-filedaemon-mariabackup-python-plugin + plugin_dir: "/usr/lib64/bareos/plugins" + plugin_names: python3 + - name: mysql + plugin_dir: "/usr/lib64/bareos/plugins" + plugin_names: python3 + - name: postgresql + package_name: bareos-filedaemon-postgresql-python-plugin + plugin_dir: "/usr/lib64/bareos/plugins" + plugin_names: python3 + - name: ldap + package_name: bareos-filedaemon-ldap-python-plugin From 6e6f3327a435a298b29b36948658610b73aa462f Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 13:08:37 +0100 Subject: [PATCH 06/11] chore(lint): tasks/plugins.yml --- tasks/plugins.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/plugins.yml b/tasks/plugins.yml index b32ee1f..6e087df 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -1,12 +1,12 @@ --- -- name: Get Bareos plugin package names +- name: plugins | Get Bareos plugin package names ansible.builtin.set_fact: - #_plugin_packages: "{{ bareos_fd_plugin_list[item.name].package_name }}" - _plugin_packages: "{{ bareos_fd_plugin_list | selectattr('name', 'match', item.name ) | map(attribute='package_name') }}" + _plugin_packages: + "{{ bareos_fd_plugin_list | selectattr('name', 'match', item.name) | map(attribute='package_name') }}" loop: "{{ bareos_fd_plugins }}" -- name: Install Bareos plugin packages +- name: plugins | Install Bareos plugin packages ansible.builtin.package: name: "{{ _plugin_packages }}" state: present From 4dc3fd004dc6fcb556f720dfe24fe7650525959f Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 13:25:27 +0100 Subject: [PATCH 07/11] fix(molecule): add fd plugin to converge.yml --- molecule/default/converge.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index e16db6a..0efb2fc 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -116,4 +116,5 @@ - "!saved" - name: "disabled-message" enabled: no - bareos_fd_plugins: [] + bareos_fd_plugins: + - mariabackup From 509f0e1168967ca742ead3970aae6c502a85bfff Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 13:45:56 +0100 Subject: [PATCH 08/11] fix(plugins): jinja indentation, conditionals --- templates/myself.conf.j2 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/myself.conf.j2 b/templates/myself.conf.j2 index 3804c5c..3259fee 100644 --- a/templates/myself.conf.j2 +++ b/templates/myself.conf.j2 @@ -29,13 +29,15 @@ Client { #} {% if bareos_fd_plugins is defined %} {% for plugin in bareos_fd_plugins %} -{% for item in bareos_fd_plugin_list if item.name == plugin %} - {% if item.plugin_dir is defined %} +{% for item in bareos_fd_plugin_list if item.name == plugin.name %} + +{% if item.plugin_dir is defined %} Plugin Directory = "{{ item.plugin_dir }}" - {% endif %} - {% if item.plugin_names is defined %} +{% endif %} +{% if item.plugin_names is defined %} Plugin Names = "{{ item.plugin_names }}" - {% endif %} +{% endif %} + {% endfor %} {% endfor %} {% endif %} From 781c743ca7cde75933d8145453d4313266a7a304 Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 14:04:58 +0100 Subject: [PATCH 09/11] fix(plugins): bareos_fd_plugins conditional is plugin not plugin.name --- tasks/plugins.yml | 2 +- templates/myself.conf.j2 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/plugins.yml b/tasks/plugins.yml index 6e087df..b863d65 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -3,7 +3,7 @@ - name: plugins | Get Bareos plugin package names ansible.builtin.set_fact: _plugin_packages: - "{{ bareos_fd_plugin_list | selectattr('name', 'match', item.name) | map(attribute='package_name') }}" + "{{ bareos_fd_plugin_list | selectattr('name', 'match', item ) | map(attribute='package_name') }}" loop: "{{ bareos_fd_plugins }}" - name: plugins | Install Bareos plugin packages diff --git a/templates/myself.conf.j2 b/templates/myself.conf.j2 index 3259fee..98bf9ca 100644 --- a/templates/myself.conf.j2 +++ b/templates/myself.conf.j2 @@ -29,7 +29,7 @@ Client { #} {% if bareos_fd_plugins is defined %} {% for plugin in bareos_fd_plugins %} -{% for item in bareos_fd_plugin_list if item.name == plugin.name %} +{% for item in bareos_fd_plugin_list if item.name == plugin %} {% if item.plugin_dir is defined %} Plugin Directory = "{{ item.plugin_dir }}" From 8d5ce2f15f209549a439cd49b8ff860361fc4b53 Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 14:09:03 +0100 Subject: [PATCH 10/11] fix(lint): spacing tasks/plugins.yml --- tasks/plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/plugins.yml b/tasks/plugins.yml index b863d65..472f72a 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -3,7 +3,7 @@ - name: plugins | Get Bareos plugin package names ansible.builtin.set_fact: _plugin_packages: - "{{ bareos_fd_plugin_list | selectattr('name', 'match', item ) | map(attribute='package_name') }}" + "{{ bareos_fd_plugin_list | selectattr('name', 'match', item) | map(attribute='package_name') }}" loop: "{{ bareos_fd_plugins }}" - name: plugins | Install Bareos plugin packages From b342dd122ec082581a18ac74f306da7e917173b2 Mon Sep 17 00:00:00 2001 From: Patrick Hasler Date: Fri, 26 Jan 2024 17:40:43 +0100 Subject: [PATCH 11/11] chore(README): add FD plugin example --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f3b8d2b..4dec7d4 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ This example is taken from [`molecule/default/converge.yml`](https://github.com/ - "!saved" - name: "disabled-message" enabled: no + bareos_fd_plugins: + - mariabackup ``` The machine needs to be prepared. In CI this is done using [`molecule/default/prepare.yml`](https://github.com/adfinis/ansible-role-bareos_fd/blob/master/molecule/default/prepare.yml):