Skip to content

Commit

Permalink
Merge pull request #3 from adfinis/update_vars
Browse files Browse the repository at this point in the history
chore: separate vars by distro, fix FD plugin integration
  • Loading branch information
adf-patrickha authored Feb 12, 2024
2 parents 961b6e4 + b1ed1cf commit b23d556
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 82 deletions.
1 change: 1 addition & 0 deletions molecule/default/collections.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

collections:
- name: community.docker
- name: community.general
29 changes: 17 additions & 12 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
1 change: 1 addition & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Ansible managed
#

dependency:
name: galaxy
options:
Expand Down
6 changes: 3 additions & 3 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 19 additions & 2 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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.*
1 change: 1 addition & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ roles:

collections:
- name: community.crypto
- name: community.general
6 changes: 6 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 10 additions & 4 deletions tasks/plugins.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 4 additions & 14 deletions templates/myself.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
}
9 changes: 9 additions & 0 deletions vars/Archlinux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

bareos_fd_encryption_packages:
- python-cryptography

bareos_fd_service: bareos-fd

bareos_fd_debug_packages:
- bareos-devel
1 change: 1 addition & 0 deletions vars/CentOS_7.yml
25 changes: 25 additions & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions vars/RedHat_7.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions vars/Suse.yml
Original file line number Diff line number Diff line change
@@ -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
51 changes: 7 additions & 44 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -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/<Distro.yml>). 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"

0 comments on commit b23d556

Please sign in to comment.