From 1fc7975323b334c3e3668cbadea2966a7b801a07 Mon Sep 17 00:00:00 2001 From: mg Date: Thu, 31 Dec 2020 01:36:22 +0100 Subject: [PATCH] Sanoid Templates als Variablen (#19) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aufräumen In GroupVars eingebaut Templates als Vars Doku aktualisiert Typo neues Dictionary-Format Vars: zfs_pool --> zfs_pools Co-authored-by: Michael Grote <38253905+quotengrote@users.noreply.github.com> Reviewed-on: https://git.mgrote.net/mg/ansible/pulls/19 Co-Authored-By: mg Co-Committed-By: mg --- group_vars/storage.yml | 78 +++++++++++++++----- group_vars/virt.yml | 59 +++++++++++++-- roles/mgrote.fileserver_smb/README.md | 20 +++++ roles/mgrote.sanoid/defaults/main.yml | 65 +++++++++------- roles/mgrote.sanoid/templates/sanoid.conf.j2 | 46 ++++-------- roles/mgrote.zfs_tools/README.md | 2 +- roles/mgrote.zfs_tools/tasks/main.yml | 4 +- 7 files changed, 190 insertions(+), 84 deletions(-) diff --git a/group_vars/storage.yml b/group_vars/storage.yml index acbe8cb0..b1e370ed 100644 --- a/group_vars/storage.yml +++ b/group_vars/storage.yml @@ -1,24 +1,68 @@ --- ### mgrote.smb_fileserver smb_nutzer: - - { name: 'annemariedroessler', groups: 'users', password: "{{ lookup('keepass', 'fileserver_smb_user_amd', 'password') }}" } - - { name: 'restic', groups: 'users', password: "{{ lookup('keepass', 'fileserver_smb_user_restic', 'password') }}" } - - { name: 'win10', groups: 'users', password: "{{ lookup('keepass', 'fileserver_smb_user_win10', 'password') }}" } - - { name: 'kodi', groups: 'users', password: "{{ lookup('keepass', 'fileserver_smb_user_kodi', 'password') }}" } - - { name: 'michaelgrote', groups: 'users', password: "{{ lookup('keepass', 'fileserver_smb_user_mg', 'password') }}" } - - { name: 'navidrome', groups: 'users', password: "{{ lookup('keepass', 'fileserver_smb_user_navidrome', 'password') }}" } - - { name: 'docker', groups: 'users', password: "{{ lookup('keepass', 'fileserver_smb_user_docker', 'password') }}" } + - name: 'annemariedroessler' + groups: 'users' + password: "{{ lookup('keepass', 'fileserver_smb_user_amd', 'password') }}" + - name: 'restic' + groups: 'users' + password: "{{ lookup('keepass', 'fileserver_smb_user_restic', 'password') }}" + - name: 'win10' + groups: 'users' + password: "{{ lookup('keepass', 'fileserver_smb_user_win10', 'password') }}" + - name: 'kodi' + groups: 'users' + password: "{{ lookup('keepass', 'fileserver_smb_user_kodi', 'password') }}" + - name: 'michaelgrote' + groups: 'users' + password: "{{ lookup('keepass', 'fileserver_smb_user_mg', 'password') }}" + - name: 'navidrome' + groups: 'users' + password: "{{ lookup('keepass', 'fileserver_smb_user_navidrome', 'password') }}" + - name: 'docker' + groups: 'users' + password: "{{ lookup('keepass', 'fileserver_smb_user_docker', 'password') }}" smb_freigaben: - - { freigabename: 'videos', ordnerpfad: '/shares_videos', lese_nutzer: ' kodi', schreibe_nutzer: 'annemariedroessler michaelgrote' } - - { freigabename: 'ag', ordnerpfad: '/shares/ag', lese_nutzer: '', schreibe_nutzer: ' michaelgrote' } - - { freigabename: 'amd', ordnerpfad: '/shares/amd', lese_nutzer: 'navidrome michaelgrote', schreibe_nutzer: 'annemariedroessler' } - - { freigabename: 'backup', ordnerpfad: '/shares/Backup', lese_nutzer: '', schreibe_nutzer: 'annemariedroessler restic win10 michaelgrote' } - - { freigabename: 'hm', ordnerpfad: '/shares/hm', lese_nutzer: '', schreibe_nutzer: 'michaelgrote' } - - { freigabename: 'mg', ordnerpfad: '/shares/mg', lese_nutzer: '', schreibe_nutzer: 'win10 michaelgrote' } - - { freigabename: 'musik', ordnerpfad: '/shares/Musik', lese_nutzer: 'navidrome kodi annemariedroessler ', schreibe_nutzer: 'win10 michaelgrote' } - - { freigabename: 'tmp', ordnerpfad: '/shares/tmp', lese_nutzer: '', schreibe_nutzer: 'kodi annemariedroessler restic win10 michaelgrote' } - - { freigabename: 'bilder', ordnerpfad: '/shares/bilder', lese_nutzer: '', schreibe_nutzer: 'annemariedroessler michaelgrote' } - - { freigabename: 'docker', ordnerpfad: '/shares/docker', lese_nutzer: '', schreibe_nutzer: 'docker' } + - freigabename: 'videos' + ordnerpfad: '/shares_videos' + lese_nutzer: ' kodi' + schreibe_nutzer: 'annemariedroessler michaelgrote' + - freigabename: 'ag' + ordnerpfad: '/shares/ag' + lese_nutzer: '' + schreibe_nutzer: 'michaelgrote' + - freigabename: 'amd' + ordnerpfad: '/shares/amd' + lese_nutzer: 'navidrome michaelgrote' + schreibe_nutzer: 'annemariedroessler' + - freigabename: 'backup' + ordnerpfad: '/shares/Backup' + lese_nutzer: '' + schreibe_nutzer: 'annemariedroessler restic win10 michaelgrote' + - freigabename: 'hm' + ordnerpfad: '/shares/hm' + lese_nutzer: '' + schreibe_nutzer: 'michaelgrote' + - freigabename: 'mg' + ordnerpfad: '/shares/mg' + lese_nutzer: '' + schreibe_nutzer: 'win10 michaelgrote' + - freigabename: 'musik' + ordnerpfad: '/shares/Musik' + lese_nutzer: 'navidrome kodi annemariedroessler ' + schreibe_nutzer: 'win10 michaelgrote' + - freigabename: 'tmp' + ordnerpfad: '/shares/tmp' + lese_nutzer: '' + schreibe_nutzer: 'kodi annemariedroessler restic win10 michaelgrote' + - freigabename: 'bilder' + ordnerpfad: '/shares/bilder' + lese_nutzer: '' + schreibe_nutzer: 'annemariedroessler michaelgrote' + - freigabename: 'docker' + ordnerpfad: '/shares/docker' + lese_nutzer: '' + schreibe_nutzer: 'docker' smb_workgroup: WORKGROUP smb_nutzer_loeschen: diff --git a/group_vars/virt.yml b/group_vars/virt.yml index c061ffec..60c2a161 100644 --- a/group_vars/virt.yml +++ b/group_vars/virt.yml @@ -12,8 +12,31 @@ - .gitconfig ### mgrote.sanoid sanoid_datasets: - - { path: 'hdd_data_raidz/data', template: 'fiveminutes', recursive: ' no' } - - { path: 'hdd_data_raidz/videos', template: 'hourly', recursive: ' yes' } + - path: 'hdd_data_raidz/data' + template: 'fiveminutes' # muss in Templates angelegt sein + recursive: ' no' + - path: 'hdd_data_raidz/videos' + template: 'hourly' + recursive: ' yes' + sanoid_templates: + - name: 'fiveminutes' + keep_hourly: '24' # Aufheben (Stunde) + keep_daily: '31' # Aufheben (Tage) + keep_monthly: '6' # Aufheben (Monate) + keep_yearly: '0' # Aufheben (Jahre) + frequently: '36' # Aufheben (Minuten) + frequent_period: '5' # Intervall (alle 5 Minuten) + autosnap: 'yes' # Automatisches erstellen von Snapshots + autoprune: 'yes' + - name: 'hourly' + keep_hourly: '24' + keep_daily: '31' + keep_monthly: '6' + keep_yearly: '1' + frequently: '0' + frequent_period: '0' + autosnap: 'yes' + autoprune: 'yes' ### mgrote.smart smart_smartctlmail_cron_minutes: "15" smart_smartctlmail_cron_hours: "6" @@ -29,10 +52,34 @@ NOLOGON: disable ### mgrote.zfs_tools zfs_arc_max: "12884901888" - zfs_pool: - - { name: "ssd_vm_mirror", type: "ssd", cron_minute_zfs_trim: "5", cron_hour_zfs_trim: "22", cron_month_zfs_trim: "4,8,12", cron_day_zfs_trim: "2", cron_weekday_zfs_scrub: "6", cron_minutes_zfs_scrub: "0", cron_hour_zfs_scrub: "23"} - - { name: "hdd_vm_mirror", type: "hdd", cron_minute_zfs_trim: "5", cron_hour_zfs_trim: "23", cron_month_zfs_trim: "4,8,12", cron_day_zfs_trim: "2", cron_weekday_zfs_scrub: "6", cron_minutes_zfs_scrub: "0", cron_hour_zfs_scrub: "22"} - - { name: "hdd_data_raidz", type: "hdd", cron_minute_zfs_trim: "5", cron_hour_zfs_trim: "24", cron_month_zfs_trim: "4,8,12", cron_day_zfs_trim: "2", cron_weekday_zfs_scrub: "6", cron_minutes_zfs_scrub: "0", cron_hour_zfs_scrub: "23"} + zfs_pools: + - name: "ssd_vm_mirror" + type: "ssd" + cron_minute_zfs_trim: "5" + cron_hour_zfs_trim: "22" + cron_month_zfs_trim: "4,8,12" + cron_day_zfs_trim: "2" + cron_weekday_zfs_scrub: "6" + cron_minutes_zfs_scrub: "0" + cron_hour_zfs_scrub: "23" + - name: "hdd_vm_mirror" + type: "hdd" + cron_minute_zfs_trim: "5" + cron_hour_zfs_trim: "23" + cron_month_zfs_trim: "4,8,12" + cron_day_zfs_trim: "2" + cron_weekday_zfs_scrub: "6" + cron_minutes_zfs_scrub: "0" + cron_hour_zfs_scrub: "22" + - name: "hdd_data_raidz" + type: "hdd" + cron_minute_zfs_trim: "5" + cron_hour_zfs_trim: "24" + cron_month_zfs_trim: "4,8,12" + cron_day_zfs_trim: "2" + cron_weekday_zfs_scrub: "6" + cron_minutes_zfs_scrub: "0" + cron_hour_zfs_scrub: "23" ### mgrote.cv4pve-autosnap cv4pve_api_user: root@pam!cv4pve-autosnap cv4pve_api_token: "{{ lookup('keepass', 'cv4pve_api_token', 'password') }}" diff --git a/roles/mgrote.fileserver_smb/README.md b/roles/mgrote.fileserver_smb/README.md index 2ec87225..6b831fa7 100644 --- a/roles/mgrote.fileserver_smb/README.md +++ b/roles/mgrote.fileserver_smb/README.md @@ -31,3 +31,23 @@ Es sind keine "defaults" gesetzt! - { freigabename: 'Backup', ordnername: 'Backup', base_folder: '/shares', lese_nutzer: '', schreibe_nutzer: 'annemariedroessler mg restic toolserver win10' } ##### Welche "Arbeitsgruppe" smb_workgroup: WORKGROUP + + +## Alternatives Dictionary Format: +```bash + zfs_pools: + - name: "ssd_vm_mirror" + type: "ssd" + cron_minute_zfs_trim: "5" + cron_hour_zfs_trim: "22" + cron_month_zfs_trim: "4,8,12" + cron_day_zfs_trim: "2" + cron_weekday_zfs_scrub: "6" + cron_minutes_zfs_scrub: "0" + cron_hour_zfs_scrub: "23" +``` +ist das gleiche wie: +```bash + zfs_pools: + - { name: "ssd_vm_mirror", type: "ssd", cron_minute_zfs_trim: "5", cron_hour_zfs_trim: "22", cron_month_zfs_trim: "4,8,12", cron_day_zfs_trim: "2", cron_weekday_zfs_scrub: "6", cron_minutes_zfs_scrub: "0", cron_hour_zfs_scrub: "23"} +``` diff --git a/roles/mgrote.sanoid/defaults/main.yml b/roles/mgrote.sanoid/defaults/main.yml index 78c32a67..3dfdbe13 100644 --- a/roles/mgrote.sanoid/defaults/main.yml +++ b/roles/mgrote.sanoid/defaults/main.yml @@ -1,34 +1,43 @@ --- - # Wann soll das sanoid-script mit cron ausgeführt werden? (Stunden) + # Wann soll das sanoid-script mit cron ausgeführt werden? sanoid_cron_hours: '*' - # Wann soll das sanoid-script mit cron ausgeführt werden? (Minuten) sanoid_cron_minutes: '*' - ### Definition der Variablen für die sanoid-templates- - # template_fiveminutes - sanoid_template_fiveminutes_snapshot_keep_hourly: '24' # Aufheben (Stunde) - sanoid_template_fiveminutes_snapshot_keep_daily: '31' # Aufheben (Tage) - sanoid_template_fiveminutes_snapshot_keep_monthly: '6' # Aufheben (Monate) - sanoid_template_fiveminutes_snapshot_keep_yearly: '0' # Aufheben (Jahre) - sanoid_template_fiveminutes_snapshot_interval_underhour: '5' # Intervall (alle 5 Minuten) - sanoid_template_fiveminutes_snapshot_keep_underhour: '36' # Aufheben (Minuten) - sanoid_template_fiveminutes_auto_snap: 'yes' # Automatisches erstellen von Snapshots - sanoid_template_fiveminutes_prune: 'yes' # Automatisches Löschen/Prunen alter Snapshots - # template_hourly - sanoid_template_hourly_snapshot_keep_hourly: '24' - sanoid_template_hourly_snapshot_keep_daily: '31' - sanoid_template_hourly_snapshot_keep_monthly: '6' - sanoid_template_hourly_snapshot_keep_yearly: '1' - sanoid_template_hourly_auto_snap: 'yes' - sanoid_template_hourly_prune: 'yes' - # template_daily - sanoid_template_daily_snapshot_keep_daily: '31' - sanoid_template_daily_snapshot_keep_monthly: '6' - sanoid_template_daily_snapshot_keep_yearly: '1' - sanoid_template_daily_auto_snap: 'yes' - sanoid_template_daily_prune: 'yes' - ### "Default" Datasets sanoid_datasets: - - { path: 'hdd_data_raidz/data', template: 'fiveminutes', recursive: ' no' } - - { path: 'hdd_data_raidz/videos', template: 'hourly', recursive: ' yes' } + - path: 'hdd_data_raidz/data' + template: 'fiveminutes' + recursive: ' no' + - path: 'hdd_data_raidz/videos' + template: 'hourly' + recursive: ' yes' + + ### Templates + sanoid_templates: + - name: 'fiveminutes' + keep_hourly: '24' # Aufheben (Stunde) + keep_daily: '31' # Aufheben (Tage) + keep_monthly: '6' # Aufheben (Monate) + keep_yearly: '0' # Aufheben (Jahre) + frequently: '36' # Aufheben (Minuten) + frequent_period: '5' # Intervall (alle 5 Minuten) + autosnap: 'yes' # Automatisches erstellen von Snapshots + autoprune: 'yes' + - name: 'hourly' + keep_hourly: '24' + keep_daily: '31' + keep_monthly: '6' + keep_yearly: '1' + frequently: '0' + frequent_period: '0' + autosnap: 'yes' + autoprune: 'yes' + - name: 'daily' + keep_hourly: '0' + keep_daily: '31' + keep_monthly: '6' + keep_yearly: '1' + frequently: '0' + frequent_period: '0' + autosnap: 'yes' + autoprune: 'yes' diff --git a/roles/mgrote.sanoid/templates/sanoid.conf.j2 b/roles/mgrote.sanoid/templates/sanoid.conf.j2 index a8afb290..2e7fff6b 100644 --- a/roles/mgrote.sanoid/templates/sanoid.conf.j2 +++ b/roles/mgrote.sanoid/templates/sanoid.conf.j2 @@ -1,40 +1,26 @@ -## ZFS Section ## +## ZFS Section -------------------------------- ## {% for item in sanoid_datasets %} [{{ item.path }}] use_template = {{ item.template }} recursive = {{ item.recursive }} -## ----------- ## +## -------------------------------------------- ## {% endfor %} -## Template Section ## -[template_fiveminutes] +## Template Section --------------------------- ## +{% for item in sanoid_templates %} +[template_{{ item.name }}] ## Keep-Rules - hourly = {{ sanoid_template_fiveminutes_snapshot_keep_hourly }} - daily = {{ sanoid_template_fiveminutes_snapshot_keep_daily }} - monthly = {{ sanoid_template_fiveminutes_snapshot_keep_monthly }} - yearly = {{ sanoid_template_fiveminutes_snapshot_keep_yearly }} - frequently = {{ sanoid_template_fiveminutes_snapshot_keep_underhour }} - ## Underhour intervall - frequent_period = {{ sanoid_template_fiveminutes_snapshot_interval_underhour }} + hourly = {{ item.keep_hourly }} + daily = {{ item.keep_daily }} + monthly = {{ item.keep_monthly }} + yearly = {{ item.keep_yearly }} + frequently = {{ item.frequently }} + ## Interval + frequent_period = {{ item.frequent_period }} ## Other Options - autosnap = {{ sanoid_template_fiveminutes_auto_snap }} - autoprune = {{ sanoid_template_fiveminutes_prune }} -[template_hourly] - ## Keep-Rules - hourly = {{ sanoid_template_hourly_snapshot_keep_hourly }} - daily = {{ sanoid_template_hourly_snapshot_keep_daily }} - monthly = {{ sanoid_template_hourly_snapshot_keep_monthly }} - yearly = {{ sanoid_template_hourly_snapshot_keep_yearly }} - ## Other Options - autosnap = {{ sanoid_template_hourly_auto_snap }} - autoprune = {{ sanoid_template_hourly_prune }} -[template_daily] - ## Keep-Rules - daily = {{ sanoid_template_daily_snapshot_keep_daily }} - monthly = {{ sanoid_template_daily_snapshot_keep_monthly }} - yearly = {{ sanoid_template_daily_snapshot_keep_yearly }} - ## Other Options - autosnap = {{ sanoid_template_daily_auto_snap }} - autoprune = {{ sanoid_template_daily_prune }} + autosnap = {{ item.autosnap }} + autoprune = {{ item.autoprune }} +## -------------------------------------------- ## +{% endfor %} diff --git a/roles/mgrote.zfs_tools/README.md b/roles/mgrote.zfs_tools/README.md index 652df2ad..aa5076aa 100644 --- a/roles/mgrote.zfs_tools/README.md +++ b/roles/mgrote.zfs_tools/README.md @@ -14,7 +14,7 @@ Deaktiviert das mitinstallierte scrub-Script in /etc/cron.d/zfsutils-linux. ### Variablen + Defaults ##### Wer soll die Mails bekommen empfaenger_mail: michael.grote@posteo.de -zfs_pool: zfs_vm_mirror +zfs_pools: zfs_vm_mirror ##### Maximale Groesse ARC in Bytes Beim aendern wird die Zeile einmal mit dem alten Wert und dem neuen Wert in die Zeile eingefuegt! zfs_arc_max: "8589934592" diff --git a/roles/mgrote.zfs_tools/tasks/main.yml b/roles/mgrote.zfs_tools/tasks/main.yml index 9f6dc0ce..fadc2bc8 100644 --- a/roles/mgrote.zfs_tools/tasks/main.yml +++ b/roles/mgrote.zfs_tools/tasks/main.yml @@ -52,7 +52,7 @@ weekday: "{{ item.cron_weekday_zfs_scrub }}" minute: "{{ item.cron_minutes_zfs_scrub }}" hour: "{{ item.cron_hour_zfs_scrub }}" - with_items: "{{ zfs_pool }}" + with_items: "{{ zfs_pools }}" - name: lege cronjob fuer "zfs-trim" an become: yes @@ -66,7 +66,7 @@ day: "{{ item.cron_day_zfs_trim }}" # disabled: yes when: item.type == 'ssd' - with_items: "{{ zfs_pool }}" + with_items: "{{ zfs_pools }}" - name: kopiere zed.rc become: yes