diff --git a/molecule/default/collections.yml b/molecule/default/collections.yml index b869f41..020687f 100644 --- a/molecule/default/collections.yml +++ b/molecule/default/collections.yml @@ -1,4 +1,5 @@ --- + collections: - name: community.docker - name: community.general diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 0efb2fc..435a7ab 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,14 +1,14 @@ --- - name: Converge hosts: all - become: yes - gather_facts: yes + become: true + gather_facts: true roles: - role: ansible-role-bareos_fd - bareos_fd_backup_configurations: yes - bareos_fd_install_debug_packages: yes - bareos_fd_encryption_enabled: yes + bareos_fd_backup_configurations: true + bareos_fd_install_debug_packages: true + bareos_fd_encryption_enabled: true bareos_fd_encryption_private_key: | -----BEGIN RSA PRIVATE KEY----- MIIJKAIBAAKCAgEAvFS5DDxBm2Hgf6LM2QnU3eKTw6PHpCBESjuqoKDnwnjL9wXH @@ -88,13 +88,13 @@ bareos_fd_directors: - name: "bareos-dir" password: "secretpassword" - monitor: no - connection_from_client_to_director: yes - connection_from_director_to_client: no - tls_enable: yes - tls_verify_peer: no + monitor: false + connection_from_client_to_director: true + connection_from_director_to_client: false + tls_enable: true + tls_verify_peer: false - name: "disabled-director" - enabled: no + enabled: false bareos_fd_messages: - name: "Standard" director: @@ -115,6 +115,11 @@ - "!skipped" - "!saved" - name: "disabled-message" - enabled: no + enabled: false bareos_fd_plugins: - mariabackup + - mysql + - postgresql + # TODO disabled as package `bareos-filedaemon-ldap-python-plugin` + # has broken dependencies on Debian (python-ldap instead of python3-ldap) + # - ldap diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index e918d24..0440f3a 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -2,6 +2,7 @@ # # Ansible managed # + dependency: name: galaxy options: diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index c980188..4d0a5dd 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -1,10 +1,10 @@ --- - name: Prepare hosts: all - become: yes - gather_facts: no + become: true + gather_facts: false roles: - role: robertdebock.bootstrap - role: adfinis.bareos_repository - bareos_repository_enable_tracebacks: yes + bareos_repository_enable_tracebacks: true diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 4f4d6d8..e0719ac 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,8 +1,8 @@ --- - name: Verify hosts: all - become: yes - gather_facts: no + become: true + gather_facts: true tasks: - name: Check if port 9102 is listening @@ -16,3 +16,20 @@ register: bareos_fd_test_config failed_when: - bareos_fd_test_config.stdout_lines is search("There are configuration warnings") + + # have to be specified in converge.yml: `bareos_fd_plugins` + - name: Check if plugin packages were installed + ansible.builtin.package: + name: + - bareos-filedaemon-mariabackup-python-plugin + - bareos-filedaemon-postgresql-python-plugin + # TODO disabled as package `bareos-filedaemon-ldap-python-plugin` + # has broken dependencies on Debian (python-ldap instead of python3-ldap) + # - bareos-filedaemon-ldap-python-plugin + state: present + check_mode: true + diff: true + register: _result + failed_when: _result.changed + when: + - ansible_facts.os_family != "Archlinux" # not supported for FD Plugins diff --git a/requirements.txt b/requirements.txt index dba7154..76ee97c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ # Pinning ansible-compat version due to [bug](https://github.com/ansible-community/molecule/issues/3903) -ansible-compat == 3.0.2 -molecule == 5.* -molecule-plugins[docker] == 23.* +ansible-compat == 4.* +molecule == 6.* +molecule-plugins == 23.* +docker == 7.* ansible-lint == 6.* paramiko == 3.* diff --git a/requirements.yml b/requirements.yml index bb33858..0ee4cb4 100644 --- a/requirements.yml +++ b/requirements.yml @@ -5,3 +5,4 @@ roles: collections: - name: community.crypto + - name: community.general diff --git a/tasks/main.yml b/tasks/main.yml index 020dce3..93b9423 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,6 +1,12 @@ --- # tasks file for bareos_fd +- name: Include OS-specific vars + ansible.builtin.include_vars: "{{ item }}" + with_first_found: + - "{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_major_version }}.yml" + - "{{ ansible_facts.os_family }}.yml" + - name: Import assert.yml ansible.builtin.import_tasks: file: assert.yml diff --git a/tasks/plugins.yml b/tasks/plugins.yml index 472f72a..7f05f79 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -1,12 +1,18 @@ --- -- name: plugins | Get Bareos plugin package names +- name: plugins | Get data ansible.builtin.set_fact: - _plugin_packages: - "{{ bareos_fd_plugin_list | selectattr('name', 'match', item) | map(attribute='package_name') }}" + _plugin_data: >- + {{ _plugin_data + (bareos_fd_plugin_list | selectattr('name', 'equalto', item) | list) }} loop: "{{ bareos_fd_plugins }}" + vars: + _plugin_data: [] # empty list to append to - name: plugins | Install Bareos plugin packages ansible.builtin.package: - name: "{{ _plugin_packages }}" + name: "{{ item.packages }}" state: present + loop: "{{ _plugin_data }}" + notify: + - Check configuration + - Restart bareos-filedaemon diff --git a/templates/myself.conf.j2 b/templates/myself.conf.j2 index 98bf9ca..f53bbea 100644 --- a/templates/myself.conf.j2 +++ b/templates/myself.conf.j2 @@ -24,21 +24,11 @@ Client { {% endif %} {# - bareos_fd_plugins is defined on host/group level, - while bareos_fd_plugin_list is a role var, with all available plugins +# `bareos_fd_plugins` is a list defined on host/group level, +# while `bareos_fd_plugin_name` and `bareos_fd_plugin_dir` are role vars #} {% 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 %} + Plugin Names = "{{ bareos_fd_plugin_name }}" + Plugin Directory = "{{ bareos_fd_plugin_dir }}" {% endif %} } diff --git a/vars/Archlinux.yml b/vars/Archlinux.yml new file mode 100644 index 0000000..3d4653c --- /dev/null +++ b/vars/Archlinux.yml @@ -0,0 +1,9 @@ +--- + +bareos_fd_encryption_packages: + - python-cryptography + +bareos_fd_service: bareos-fd + +bareos_fd_debug_packages: + - bareos-devel diff --git a/vars/CentOS_7.yml b/vars/CentOS_7.yml new file mode 120000 index 0000000..105e630 --- /dev/null +++ b/vars/CentOS_7.yml @@ -0,0 +1 @@ +RedHat_7.yml \ No newline at end of file diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..f9bece5 --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,25 @@ +--- + +bareos_fd_debug_packages: + - bareos-dbg + - gdb + +bareos_fd_plugin_dir: "/usr/lib/bareos/plugins" +bareos_fd_plugin_name: python3 +bareos_fd_plugin_list: + - name: mariabackup + packages: + - bareos-filedaemon-mariabackup-python-plugin + + - name: mysql + packages: + - python3-mysqldb + + - name: postgresql + packages: + - bareos-filedaemon-postgresql-python-plugin + + - name: ldap + packages: + - python3-ldap + - bareos-filedaemon-ldap-python-plugin diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..ff0a2e1 --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,26 @@ +--- + +bareos_fd_debug_packages: + - bareos-filedaemon-debuginfo + - gdb + +bareos_fd_plugin_dir: "/usr/lib64/bareos/plugins" +bareos_fd_plugin_name: python3 +bareos_fd_plugin_list: + - name: mariabackup + packages: + - bareos-filedaemon-mariabackup-python-plugin + + # TODO RHEL offers no python-mysqlclient package per default. + # Check if PyMySQL is working with the plugin + - name: mysql + packages: + - python3-PyMySQL + + - name: postgresql + packages: + - bareos-filedaemon-postgresql-python-plugin + + - name: ldap + packages: + - bareos-filedaemon-ldap-python-plugin diff --git a/vars/RedHat_7.yml b/vars/RedHat_7.yml new file mode 100644 index 0000000..f584714 --- /dev/null +++ b/vars/RedHat_7.yml @@ -0,0 +1,27 @@ +--- + +bareos_fd_encryption_packages: + - python2-cryptography + +bareos_fd_debug_packages: + - bareos-debuginfo + - gdb + +bareos_fd_plugin_dir: "/usr/lib64/bareos/plugins" +bareos_fd_plugin_name: python +bareos_fd_plugin_list: + - name: mariabackup + packages: + - bareos-filedaemon-mariabackup-python-plugin + + - name: mysql + packages: + - MySQL-python + + - name: postgresql + packages: + - bareos-filedaemon-postgresql-python-plugin + + - name: ldap + packages: + - bareos-filedaemon-ldap-python-plugin diff --git a/vars/Suse.yml b/vars/Suse.yml new file mode 100644 index 0000000..6486726 --- /dev/null +++ b/vars/Suse.yml @@ -0,0 +1,23 @@ +--- + +bareos_fd_debug_packages: + - gdb + +bareos_fd_plugin_dir: "/usr/lib64/bareos/plugins" +bareos_fd_plugin_name: python3 +bareos_fd_plugin_list: + - name: mariabackup + packages: + - bareos-filedaemon-mariabackup-python-plugin + + - name: mysql + packages: + - python3-mysqlclient + + - name: postgresql + packages: + - bareos-filedaemon-postgresql-python-plugin + + - name: ldap + packages: + - bareos-filedaemon-ldap-python-plugin diff --git a/vars/main.yml b/vars/main.yml index 3c55bb4..74ade9d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,49 +1,12 @@ --- # vars file for bareos_fd -# A map to define the packages to install for encryption. -_bareos_fd_encryption_packages: - default: - - python3-cryptography - Archlinux: - - python-cryptography - RedHat-7: - - python2-cryptography -bareos_fd_encryption_packages: "{{ _bareos_fd_encryption_packages[ansible_os_family ~ '-' ~ ansible_distribution_major_version] | default(_bareos_fd_encryption_packages[ansible_os_family]) | default(_bareos_fd_encryption_packages['default']) }}" +bareos_fd_encryption_packages: + - python3-cryptography -# A map to define the service name to manage. -_bareos_fd_service: - default: bareos-filedaemon - Archlinux: bareos-fd -bareos_fd_service: "{{ _bareos_fd_service[ansible_os_family] | default(_bareos_fd_service['default']) }}" +bareos_fd_service: bareos-filedaemon +bareos_fd_plugin_name: python3 -# A map to define the packages to install for debugging. -_bareos_fd_debug_packages: - default: - - bareos-filedaemon-debuginfo - - gdb - Archlinux: - - bareos-devel - Debian: - - bareos-dbg - - gdb - RedHat-7: - - 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 +# define the following stuff on Distro level (vars/). If a Distro is not there, it's not supported. +# bareos_fd_plugin_list: every distro might have different package names and dependencies +# bareos_fd_plugin_dir: /usr/lib on Debian, /usr/lib64 on "others"