diff --git a/group_vars/all b/group_vars/all index f56917b1..927fdbf1 100644 --- a/group_vars/all +++ b/group_vars/all @@ -49,7 +49,7 @@ on_calendar_renew_lets_encrypt_certificates: "*-*-* 12,00:30:00" on_calendar_deploy_mailu_certificates: "*-*-* 13,01:30:00" # Deploy Mailu certificates twice per day on_calendar_msi_keyboard_color: "*-*-* *:*:00" # Change the keyboard color every minute on_calendar_cleanup_failed_docker: "*-*-* 12:00:00" # Clean up failed docker backups every noon - +on_calendar_btrfs_auto_balancer: "Sat *-*-01..07 00:00:00" # Execute btrfs auto balancer every first Saturday of a month # Storage Space-Related Configurations size_percent_maximum_backup: 75 # Maximum storage space in percent for backups diff --git a/playbook.servers.yml b/playbook.servers.yml index 090f5a07..a7587fa7 100644 --- a/playbook.servers.yml +++ b/playbook.servers.yml @@ -11,6 +11,8 @@ - health-disc-space - cleanup-disc-space - health-btrfs + - system-btrfs-auto-balancer + # Docker Roles - name: setup nextcloud hosts diff --git a/roles/system-btrfs-auto-balancer/README.md b/roles/system-btrfs-auto-balancer/README.md new file mode 100644 index 00000000..a905353f --- /dev/null +++ b/roles/system-btrfs-auto-balancer/README.md @@ -0,0 +1,30 @@ +# System Btrfs Auto Balancer Role 📦 + +This Ansible role automates the management and balancing of Btrfs file systems. It ensures that the Btrfs file system is maintained efficiently without manual intervention. + +## Features ✨ + +- **Automatic Cloning of Repository:** Fetches the latest `auto-btrfs-balancer` repository from GitHub. +- **Systemd Service Configuration:** Creates and configures a Systemd service to automatically run the balancing script. +- **Systemd Timer Integration:** Integrates a Systemd timer to run the balancing service at regular intervals. +- **Error Notification:** Notifies via Systemd in case of errors during the balancing process. + +## Prerequisites 📋 + +- **Ansible:** This role requires Ansible to run. +- **Systemd:** Target systems must support Systemd. +- **Git:** Git must be installed to clone the repository. + + +## Author ✍️ + +This role was created by [Kevin Veen-Birkenbach](https://www.veen.world). +- **Email:** kevin@veen.world +- **Website:** [veen.world](https://www.veen.world) + +## Contact ☎️ + +For questions or support, you can reach Kevin Veen-Birkenbach via [email](mailto:kevin@veen.world). + +## Created with AI +This README.md was created with the assistance of ChatGPT. You can view the conversation [here](https://chatgpt.com/share/dcec1b4a-c7a8-4cf8-a87a-987eb0500857). diff --git a/roles/system-btrfs-auto-balancer/handlers/main.yml b/roles/system-btrfs-auto-balancer/handlers/main.yml new file mode 100644 index 00000000..cbd52a8b --- /dev/null +++ b/roles/system-btrfs-auto-balancer/handlers/main.yml @@ -0,0 +1,4 @@ +- name: "reload system-btrfs-auto-balancer.cymais.service" + systemd: + name: system-btrfs-auto-balancer.cymais.service + daemon_reload: yes \ No newline at end of file diff --git a/roles/system-btrfs-auto-balancer/meta/main.yml b/roles/system-btrfs-auto-balancer/meta/main.yml new file mode 100644 index 00000000..23ff4d5f --- /dev/null +++ b/roles/system-btrfs-auto-balancer/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - git + - systemd-notifier \ No newline at end of file diff --git a/roles/system-btrfs-auto-balancer/tasks/main.yml b/roles/system-btrfs-auto-balancer/tasks/main.yml new file mode 100644 index 00000000..4c665390 --- /dev/null +++ b/roles/system-btrfs-auto-balancer/tasks/main.yml @@ -0,0 +1,31 @@ +- name: pull auto-btrfs-balancer.git + git: + repo: "https://github.com/kevinveenbirkenbach/auto-btrfs-balancer.git" + dest: "{{system_btrfs_auto_balancer_folder}}" + update: yes + ignore_errors: true + when: run_once_system_btrfs_auto_balancer is not defined + +- name: configure system-btrfs-auto-balancer.cymais.service + template: + src: system-btrfs-auto-balancer.service.j2 + dest: /etc/systemd/system/system-btrfs-auto-balancer.cymais.service + notify: reload system-btrfs-auto-balancer.cymais.service + when: run_once_system_btrfs_auto_balancer is not defined + +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_system_btrfs_auto_balancer is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_btrfs_auto_balancer}}" + when: run_once_system_btrfs_auto_balancer is not defined + +- name: run the system_btrfs_auto_balancer tasks once + set_fact: + run_once_system_btrfs_auto_balancer: true + when: run_once_system_btrfs_auto_balancer is not defined diff --git a/roles/system-btrfs-auto-balancer/templates/system-btrfs-auto-balancer.service.j2 b/roles/system-btrfs-auto-balancer/templates/system-btrfs-auto-balancer.service.j2 new file mode 100644 index 00000000..2be59062 --- /dev/null +++ b/roles/system-btrfs-auto-balancer/templates/system-btrfs-auto-balancer.service.j2 @@ -0,0 +1,7 @@ +[Unit] +Description=auto balance btrfs +OnFailure=systemd-notifier.cymais@%n.service + +[Service] +Type=oneshot +ExecStart=/bin/sh -c '/usr/bin/python {{system_btrfs_auto_balancer_folder}}main.py 90 10' \ No newline at end of file diff --git a/roles/system-btrfs-auto-balancer/vars/main.yml b/roles/system-btrfs-auto-balancer/vars/main.yml new file mode 100644 index 00000000..fc4d7ccf --- /dev/null +++ b/roles/system-btrfs-auto-balancer/vars/main.yml @@ -0,0 +1 @@ +system_btrfs_auto_balancer_folder: "{{path_administrator_scripts}}auto-btrfs-balancer/" \ No newline at end of file