From 6a4dea358224f4b70109a20b8075600f2055fe28 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 26 Apr 2023 14:38:02 +0200 Subject: [PATCH] Refactored --- group_vars/all | 7 +++++-- roles/independent_user-administrator/tasks/main.yml | 4 ++-- roles/server_docker-akaunting/README.md | 2 +- roles/server_docker-mailu/tasks/main.yml | 6 +++--- .../templates/deploy-letsencrypt-mailu.service.j2 | 2 +- roles/server_docker-nextcloud/README.md | 4 ++-- roles/server_native-backups-cleanup/vars/main.yml | 2 +- roles/server_native-backups-consumer/vars/main.yml | 2 +- roles/server_native-btrfs-health-check/vars/main.yml | 2 +- roles/server_native-disc-space-check/vars/main.yml | 2 +- .../vars/main.yml | 2 +- roles/server_native-docker-health-check/vars/main.yml | 2 +- roles/server_native-docker-volume-backup/vars/main.yml | 2 +- .../templates/free-disc-space.sh.j2 | 2 +- roles/server_native-free-disc-space/vars/main.yml | 2 +- .../vars/main.yml | 2 +- roles/server_native-systemd-email/vars/main.yml | 2 +- roles/server_user-administrator/tasks/main.yml | 10 +++++----- 18 files changed, 30 insertions(+), 27 deletions(-) diff --git a/group_vars/all b/group_vars/all index 08508a6a..b6ee55b9 100644 --- a/group_vars/all +++ b/group_vars/all @@ -16,6 +16,7 @@ on_calendar_docker_compose_restart_unhealthy: "*-*-* 09,10,11,12,13,14,15,16,17, on_calendar_pull_primary_backups: "*-*-* 21:30:00" on_calendar_renew_lets_encrypt_certificates: "*-*-* 12,00:30:00" on_calendar_deploy_mailu_certificates: "*-*-* 13,01:30:00" +on_calendar_usb_auto_backup: "*-*-* 09,12,15,18,21,24,03,06:30:00" # Space Variables size_percent_maximum_backup: 75 @@ -23,5 +24,7 @@ size_percent_disc_space_warning: 85 size_percent_free_disc_space: 90 # Path Variables -path_docker_volumes: "/home/administrator/volumes/docker/" -path_docker_compose_files: "/home/administrator/docker-compose/" \ No newline at end of file +path_administrator_home: "/home/administrator/" +path_administrator_scripts: "{{path_administrator_home}}scripts/" +path_docker_volumes: "{{path_administrator_home}}volumes/docker/" +path_docker_compose_files: "{{path_administrator_home}}docker-compose/" \ No newline at end of file diff --git a/roles/independent_user-administrator/tasks/main.yml b/roles/independent_user-administrator/tasks/main.yml index 8b8cdf84..7aa2cee6 100644 --- a/roles/independent_user-administrator/tasks/main.yml +++ b/roles/independent_user-administrator/tasks/main.yml @@ -8,9 +8,9 @@ ssh_key_type: rsa ssh_key_bits: 8192 -- name: "create /home/administrator/scripts/" +- name: "create {{path_administrator_scripts}}" file: - path: "/home/administrator/scripts" + path: "{{path_administrator_home}}scripts" state: directory owner: administrator group: administrator diff --git a/roles/server_docker-akaunting/README.md b/roles/server_docker-akaunting/README.md index 4c7163ea..2f07ebb9 100644 --- a/roles/server_docker-akaunting/README.md +++ b/roles/server_docker-akaunting/README.md @@ -81,7 +81,7 @@ docker-compose build && docker-compose -p akaunting up -d --force-recreate # recover all volumes -cd /home/administrator/scripts/docker-volume-backup && +cd {{path_administrator_scripts}}docker-volume-backup && bash server_docker-volume-recover.sh akaunting_akaunting-modules ${machine_id:0:64} "$backup_version" && bash server_docker-volume-recover.sh akaunting_akaunting-data ${machine_id:0:64} "$backup_version" && bash server_docker-volume-recover.sh akaunting_akaunting-db ${machine_id:0:64} "$backup_version" akaunting-db "$akaunting_db_password" akaunting diff --git a/roles/server_docker-mailu/tasks/main.yml b/roles/server_docker-mailu/tasks/main.yml index 038fb9b5..79bffc96 100644 --- a/roles/server_docker-mailu/tasks/main.yml +++ b/roles/server_docker-mailu/tasks/main.yml @@ -15,9 +15,9 @@ state: directory mode: 0755 -- name: "create /home/administrator/scripts/mailu" +- name: "create {{path_administrator_scripts}}mailu" file: - path: "/home/administrator/scripts/mailu" + path: "{{path_administrator_scripts}}mailu" state: directory mode: 0755 @@ -48,7 +48,7 @@ - name: add deploy-letsencrypt-mailu.sh template: src: "deploy-letsencrypt-mailu.sh.j2" - dest: "/home/administrator/scripts/mailu/deploy-letsencrypt-mailu.sh" + dest: "{{path_administrator_scripts}}mailu/deploy-letsencrypt-mailu.sh" - name: configure deploy-letsencrypt-mailu.service template: diff --git a/roles/server_docker-mailu/templates/deploy-letsencrypt-mailu.service.j2 b/roles/server_docker-mailu/templates/deploy-letsencrypt-mailu.service.j2 index fb5472d1..c5f00e25 100644 --- a/roles/server_docker-mailu/templates/deploy-letsencrypt-mailu.service.j2 +++ b/roles/server_docker-mailu/templates/deploy-letsencrypt-mailu.service.j2 @@ -4,4 +4,4 @@ OnFailure=systemd-email@%n.service [Service] Type=oneshot -ExecStart=/usr/bin/bash /home/administrator/scripts/mailu/deploy-letsencrypt-mailu.sh +ExecStart=/usr/bin/bash {{path_administrator_scripts}}mailu/deploy-letsencrypt-mailu.sh diff --git a/roles/server_docker-nextcloud/README.md b/roles/server_docker-nextcloud/README.md index 53ed7487..0a1e285d 100644 --- a/roles/server_docker-nextcloud/README.md +++ b/roles/server_docker-nextcloud/README.md @@ -13,7 +13,7 @@ NEXTCLOUD_APPLICATION_DOCKER_CONTAINER=nextcloud-application-1 To update the nextcloud container execute the following commands on the server: ```bash docker exec -it -u www-data $NEXTCLOUD_APPLICATION_DOCKER_CONTAINER /var/www/html/occ maintenance:mode --on - sudo python /home/administrator/scripts/docker-volume-backup/docker-volume-backup.py + sudo python {{path_administrator_scripts}}docker-volume-backup/docker-volume-backup.py export COMPOSE_HTTP_TIMEOUT=600 export DOCKER_CLIENT_TIMEOUT=600 cd {{path_docker_compose_files}}nextcloud && docker-compose down @@ -58,7 +58,7 @@ and disable the not functioning apps. cd {{path_docker_compose_files}}nextcloud && docker-compose down && docker exec -i nextcloud_database_1 mysql -u nextcloud -pPASSWORT nextcloud < "/Backups/$(sha256sum /etc/machine-id | head -c 64)/docker-volume-backup/latest/nextcloud_database/sql/backup.sql" && -cd /home/administrator/scripts/docker-volume-backup && +cd {{path_administrator_scripts}}docker-volume-backup && bash ./server_docker-volume-recover.sh "nextcloud_data" "$(sha256sum /etc/machine-id | head -c 64)" ``` diff --git a/roles/server_native-backups-cleanup/vars/main.yml b/roles/server_native-backups-cleanup/vars/main.yml index 53d8460a..2902c496 100644 --- a/roles/server_native-backups-cleanup/vars/main.yml +++ b/roles/server_native-backups-cleanup/vars/main.yml @@ -1 +1 @@ -docker_backups_cleanup: "/home/administrator/scripts/backups-cleanup/" \ No newline at end of file +docker_backups_cleanup: "{{path_administrator_scripts}}backups-cleanup/" \ No newline at end of file diff --git a/roles/server_native-backups-consumer/vars/main.yml b/roles/server_native-backups-consumer/vars/main.yml index a0370f58..e6bd36fe 100644 --- a/roles/server_native-backups-consumer/vars/main.yml +++ b/roles/server_native-backups-consumer/vars/main.yml @@ -1 +1 @@ -docker_pull_primary_backups_folder: "/home/administrator/scripts/pull-primary-backups/" \ No newline at end of file +docker_pull_primary_backups_folder: "{{path_administrator_scripts}}pull-primary-backups/" \ No newline at end of file diff --git a/roles/server_native-btrfs-health-check/vars/main.yml b/roles/server_native-btrfs-health-check/vars/main.yml index 9178636c..ba2beb66 100644 --- a/roles/server_native-btrfs-health-check/vars/main.yml +++ b/roles/server_native-btrfs-health-check/vars/main.yml @@ -1 +1 @@ -docker_btrfs_health_check_folder: "/home/administrator/scripts/btrfs-health-check/" \ No newline at end of file +docker_btrfs_health_check_folder: "{{path_administrator_scripts}}btrfs-health-check/" \ No newline at end of file diff --git a/roles/server_native-disc-space-check/vars/main.yml b/roles/server_native-disc-space-check/vars/main.yml index b545053a..1a5d05fe 100644 --- a/roles/server_native-disc-space-check/vars/main.yml +++ b/roles/server_native-disc-space-check/vars/main.yml @@ -1 +1 @@ -disc_space_check_folder: "/home/administrator/scripts/disc-space-check/" \ No newline at end of file +disc_space_check_folder: "{{path_administrator_scripts}}disc-space-check/" \ No newline at end of file diff --git a/roles/server_native-docker-compose-restart-unhealthy/vars/main.yml b/roles/server_native-docker-compose-restart-unhealthy/vars/main.yml index 113e2592..bd60144f 100644 --- a/roles/server_native-docker-compose-restart-unhealthy/vars/main.yml +++ b/roles/server_native-docker-compose-restart-unhealthy/vars/main.yml @@ -1 +1 @@ -docker_compose_restart_unhealthy: "/home/administrator/scripts/docker-compose-restart-unhealthy/" \ No newline at end of file +docker_compose_restart_unhealthy: "{{path_administrator_scripts}}docker-compose-restart-unhealthy/" \ No newline at end of file diff --git a/roles/server_native-docker-health-check/vars/main.yml b/roles/server_native-docker-health-check/vars/main.yml index eda8b6d1..4cd7774a 100644 --- a/roles/server_native-docker-health-check/vars/main.yml +++ b/roles/server_native-docker-health-check/vars/main.yml @@ -1 +1 @@ -docker_health_check_folder: "/home/administrator/scripts/server_docker-health-check/" \ No newline at end of file +docker_health_check_folder: "{{path_administrator_scripts}}server_docker-health-check/" \ No newline at end of file diff --git a/roles/server_native-docker-volume-backup/vars/main.yml b/roles/server_native-docker-volume-backup/vars/main.yml index d73c2dea..24f466b6 100644 --- a/roles/server_native-docker-volume-backup/vars/main.yml +++ b/roles/server_native-docker-volume-backup/vars/main.yml @@ -1 +1 @@ -docker_volume_backup_folder: "/home/administrator/scripts/docker-volume-backup/" \ No newline at end of file +docker_volume_backup_folder: "{{path_administrator_scripts}}docker-volume-backup/" \ No newline at end of file diff --git a/roles/server_native-free-disc-space/templates/free-disc-space.sh.j2 b/roles/server_native-free-disc-space/templates/free-disc-space.sh.j2 index 000f73b0..3268c612 100644 --- a/roles/server_native-free-disc-space/templates/free-disc-space.sh.j2 +++ b/roles/server_native-free-disc-space/templates/free-disc-space.sh.j2 @@ -25,7 +25,7 @@ if [ "$disc_use_percent_number" -gt "$minimum_percent_free_disc_space" ] || [ "$ {% if backups_folder_path is defined and size_percent_maximum_backup is defined %} echo "cleaning up backups" && - python /home/administrator/scripts/backups-cleanup/backups-cleanup.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}} || exit 2 + python {{path_administrator_scripts}}backups-cleanup/backups-cleanup.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}} || exit 2 {% endif %} if pacman -Qs $package > /dev/null ; then diff --git a/roles/server_native-free-disc-space/vars/main.yml b/roles/server_native-free-disc-space/vars/main.yml index 417f8d5e..edebb2ba 100644 --- a/roles/server_native-free-disc-space/vars/main.yml +++ b/roles/server_native-free-disc-space/vars/main.yml @@ -1 +1 @@ -free_disc_space_folder: "/home/administrator/scripts/free-disc-space/" \ No newline at end of file +free_disc_space_folder: "{{path_administrator_scripts}}free-disc-space/" \ No newline at end of file diff --git a/roles/server_native-journalctl-health-check/vars/main.yml b/roles/server_native-journalctl-health-check/vars/main.yml index 40a83e86..076169c8 100644 --- a/roles/server_native-journalctl-health-check/vars/main.yml +++ b/roles/server_native-journalctl-health-check/vars/main.yml @@ -1 +1 @@ -journalctl_health_check_folder: "/home/administrator/scripts/journalctl-health-check/" \ No newline at end of file +journalctl_health_check_folder: "{{path_administrator_scripts}}journalctl-health-check/" \ No newline at end of file diff --git a/roles/server_native-systemd-email/vars/main.yml b/roles/server_native-systemd-email/vars/main.yml index 1245b11f..8ea81977 100644 --- a/roles/server_native-systemd-email/vars/main.yml +++ b/roles/server_native-systemd-email/vars/main.yml @@ -1 +1 @@ -systemd_email_folder: "/home/administrator/scripts/systemd_email/" \ No newline at end of file +systemd_email_folder: "{{path_administrator_scripts}}systemd_email/" \ No newline at end of file diff --git a/roles/server_user-administrator/tasks/main.yml b/roles/server_user-administrator/tasks/main.yml index 76bcdadf..819b444f 100644 --- a/roles/server_user-administrator/tasks/main.yml +++ b/roles/server_user-administrator/tasks/main.yml @@ -1,7 +1,7 @@ -- name: create /home/administrator/.ssh/authorized_keys +- name: create {{path_administrator_home}}.ssh/authorized_keys copy: - src: "{{ inventory_dir }}/files/{{ inventory_hostname }}/home/administrator/.ssh/authorized_keys" - dest: /home/administrator/.ssh/authorized_keys + src: "{{ inventory_dir }}/files/{{ inventory_hostname }}{{path_administrator_home}}.ssh/authorized_keys" + dest: "{{path_administrator_home}}.ssh/authorized_keys" owner: administrator group: administrator mode: '0644' @@ -15,9 +15,9 @@ group: root notify: sshd restart -- name: "create /home/administrator/volumes/" +- name: "create {{path_administrator_home}}volumes/" file: - path: "/home/administrator/volumes" + path: "{{path_administrator_home}}volumes" state: directory owner: administrator group: administrator