diff --git a/group_vars/all.yml b/group_vars/all.yml index ef22677c..f4812539 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -111,6 +111,23 @@ - qemu-guest-agent - open-vm-tools + ### mgrote.apcupsd + apcupsd_master_onbatterydelay: 10 + apcupsd_master_batterylevel_for_shutdown: 50 + apcupsd_master_minutes_for_shutdown: 10 + apcupsd_master_nologon_when_active: disable + apcupsd_slave_onbatterydelay: 10 + apcupsd_slave_batterylevel_for_shutdown: 50 + apcupsd_slave_minutes_for_shutdown: 10 + apcupsd_slave_nologon_when_active: disable + apcupsd_nis_master: on + # apcupsd_nis_master_hostname: pve2.grote.lan # wird pro host gesetzt + apcupsd_nis_master_listen_ip: 0.0.0.0 + apcupsd_nis_master_listen_port: 3551 + apcupsd_ups_name: APC-BX950U-GR + # apcupsd_nis_master: false # wird pro host gesetzt + + # Ansible Variablen ### User ansible_user: "ansible-user" diff --git a/group_vars/proxmox.yml b/group_vars/proxmox.yml index efc5a153..615d22f6 100644 --- a/group_vars/proxmox.yml +++ b/group_vars/proxmox.yml @@ -45,11 +45,6 @@ tmux_conf_destination: "/root/.tmux.conf" tmux_bashrc_destination: "/root/.bashrc" tmux_standardsession_name: "default" - ### mgrote.apcupsd - ONBATTERYDELAY: 10 - BATTERYLEVEL: 50 - MINUTES: 10 - NOLOGON: disable ### mgrote.zfs_tools_cron zfs_arc_max: "12884901888" zfs_pools: diff --git a/host_vars/pve-test.grote.lan.yml b/host_vars/pve-test.grote.lan.yml new file mode 100644 index 00000000..178968b6 --- /dev/null +++ b/host_vars/pve-test.grote.lan.yml @@ -0,0 +1,32 @@ +--- + ### mgrote.zfs_manage_datasets + # "Daten"-Datasets verwalte ich händisch! + # zfs create -o encryption=aes-256-gcm -o keyformat=passphrase hdd_data_raidz/data_crypt + # zfs create hdd_data_raidz/videos + # Pools müssen vorher erstellt sein! + # SSD_VM_MIRROR + # zpool create -f -o ashift=12 ssd_vm_mirror mirror /dev/disk/by-id/ata-ADATA_SU650_2J4420001210 /dev/disk/by-id/ata-ADATA_SU650_2J4420001241 + # HDD_VM_MIRROR + # zpool create -f -o ashift=12 hdd_vm_mirror mirror /dev/disk/by-id/ata-WDC_WD20EACS-11BHUB0_WD-WCAZA3124223 /dev/disk/by-id/ata-WDC_WD20EZRX-00D8PB0_WD-WMC4M1682516 mirror /dev/disk/by-id/ata-WDC_WD30EZRX-00DC0B0_WD-WMC1T3979908 /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_83M2DRAKS + # HDD_DATA_RAIDZ + # zpool create -f -o ashift=12 hdd_data_raidz raidz /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SG991TJ /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SGA23EJ /dev/disk/by-id/ata-ST8000DM004-2CX188_ZCT1AK0F + zfs_datasets: + - dataset: ssd_vm_mirror/vm + state: present + compression: lz4 + sync: disabled + xattr: sa + dnodesize: auto + atime: on + snapdir: hidden + - dataset: hdd_vm_mirror/vm + state: present + compression: lz4 + sync: disabled + xattr: sa + dnodesize: auto + atime: on + snapdir: hidden + ### mgrote.apcupsd + apcupsd_nis_master: true + apcupsd_nis_master_hostname: pve-test.grote.lan diff --git a/host_vars/pve2.grote.lan.yml b/host_vars/pve2.grote.lan.yml index 1bcd4efc..6fb4eeb9 100644 --- a/host_vars/pve2.grote.lan.yml +++ b/host_vars/pve2.grote.lan.yml @@ -1,29 +1,32 @@ --- - ### mgrote.zfs_manage_datasets - # "Daten"-Datasets verwalte ich händisch! - # zfs create -o encryption=aes-256-gcm -o keyformat=passphrase hdd_data_raidz/data_crypt - # zfs create hdd_data_raidz/videos - # Pools müssen vorher erstellt sein! - # SSD_VM_MIRROR - # zpool create -f -o ashift=12 ssd_vm_mirror mirror /dev/disk/by-id/ata-ADATA_SU650_2J4420001210 /dev/disk/by-id/ata-ADATA_SU650_2J4420001241 - # HDD_VM_MIRROR - # zpool create -f -o ashift=12 hdd_vm_mirror mirror /dev/disk/by-id/ata-WDC_WD20EACS-11BHUB0_WD-WCAZA3124223 /dev/disk/by-id/ata-WDC_WD20EZRX-00D8PB0_WD-WMC4M1682516 mirror /dev/disk/by-id/ata-WDC_WD30EZRX-00DC0B0_WD-WMC1T3979908 /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_83M2DRAKS - # HDD_DATA_RAIDZ - # zpool create -f -o ashift=12 hdd_data_raidz raidz /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SG991TJ /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SGA23EJ /dev/disk/by-id/ata-ST8000DM004-2CX188_ZCT1AK0F - zfs_datasets: - - dataset: ssd_vm_mirror/vm - state: present - compression: lz4 - sync: disabled - xattr: sa - dnodesize: auto - atime: on - snapdir: hidden - - dataset: hdd_vm_mirror/vm - state: present - compression: lz4 - sync: disabled - xattr: sa - dnodesize: auto - atime: on - snapdir: hidden + ### mgrote.zfs_manage_datasets + # "Daten"-Datasets verwalte ich händisch! + # zfs create -o encryption=aes-256-gcm -o keyformat=passphrase hdd_data_raidz/data_crypt + # zfs create hdd_data_raidz/videos + # Pools müssen vorher erstellt sein! + # SSD_VM_MIRROR + # zpool create -f -o ashift=12 ssd_vm_mirror mirror /dev/disk/by-id/ata-ADATA_SU650_2J4420001210 /dev/disk/by-id/ata-ADATA_SU650_2J4420001241 + # HDD_VM_MIRROR + # zpool create -f -o ashift=12 hdd_vm_mirror mirror /dev/disk/by-id/ata-WDC_WD20EACS-11BHUB0_WD-WCAZA3124223 /dev/disk/by-id/ata-WDC_WD20EZRX-00D8PB0_WD-WMC4M1682516 mirror /dev/disk/by-id/ata-WDC_WD30EZRX-00DC0B0_WD-WMC1T3979908 /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_83M2DRAKS + # HDD_DATA_RAIDZ + # zpool create -f -o ashift=12 hdd_data_raidz raidz /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SG991TJ /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SGA23EJ /dev/disk/by-id/ata-ST8000DM004-2CX188_ZCT1AK0F + zfs_datasets: + - dataset: ssd_vm_mirror/vm + state: present + compression: lz4 + sync: disabled + xattr: sa + dnodesize: auto + atime: on + snapdir: hidden + - dataset: hdd_vm_mirror/vm + state: present + compression: lz4 + sync: disabled + xattr: sa + dnodesize: auto + atime: on + snapdir: hidden + ### mgrote.apcupsd + apcupsd_nis_master: true + apcupsd_nis_master_hostname: pve2.grote.lan diff --git a/roles/mgrote.apcupsd/README.md b/roles/mgrote.apcupsd/README.md index 48224127..9a319fe8 100644 --- a/roles/mgrote.apcupsd/README.md +++ b/roles/mgrote.apcupsd/README.md @@ -1,25 +1,68 @@ ## mgrote.apcupsd ### Beschreibung -Installiert APCUPSD fuer eine APC UPS mit USB Verbindung. -Benoetigt mgrote.postfix. -https://linux.die.net/man/5/apcupsd.conf +* Installiert apcupsd. +* Auf einem PC als "Master", hier ist die USV per USB angeschlossen. +* Auf allen anderen PCs als "Slave", diese OCs pollen alle n Sekunden den Master. +* Benoetigt mgrote.postfix. +* Getestet mit: APC-BX950U-GR + +### Links + * http://www.apcupsd.org/manual/#checking-your-configuration-file + * https://linux.die.net/man/5/apcupsd.conf + ### Funktioniert auf - [x] ProxMox 6.1 ### Variablen + Defaults -##### Wohin gehen die Benachrichtigungsmails bei Stromausfall -empfaenger_mail: michael.grote@posteo.de +##### Zeitspanne in Sekunden, ab der der Systemdienst einen Stromausfall annimmt. Nuetzlich, um sehr kurze Ausfaelle ignorieren zu koennen. Jeweils Master und Slave. +```yaml +apcupsd_master_onbatterydelay: 10 +apcupsd_slave_onbatterydelay: 10 +``` +##### Durch die USV gemeldete Restkapazitaet in Prozent, ab der der Rechner heruntergefahren wird. Jeweils Master und Slave. +```yaml +apcupsd_master_batterylevel_for_shutdown: 50 +apcupsd_slave_batterylevel_for_shutdown: 60 +``` +##### apcupsd will shutdown the system during a power failure when the remaining runtime on batteries as internally calculated by the UPS falls below the specified minutes. Jeweils Master und Slave. +```yaml +apcupsd_master_minutes_for_shutdown: 10 +apcupsd_slave_minutes_for_shutdown: 11 +``` +##### Specifies when apcupsd should create the NOLOGON file to prevent users from logging on to the system. Jeweils Master und Slave. +```yaml +apcupsd_master_nologon_when_active: always +apcupsd_slave_nologon_when_active: always +``` -##### Zeitspanne in Sekunden, ab der der Systemdienst einen Stromausfall annimmt. Nuetzlich, um sehr kurze Ausfaelle ignorieren zu koennen. -ONBATTERYDELAY: 10 +##### Ist der Server MASTER, also ist die USV an diesem Computer angeschlossen, kann nur für einen PC "true" sein. Jeweils Master und Slave. +```yaml +apcupsd_nis_master: "true" +``` -##### Durch die USV gemeldete Restkapazitaet in Prozent, ab der der Rechner heruntergefahren wird -BATTERYLEVEL: 50 +##### Wenn "true" ist dieser Host master, für alle anderen "false", das muss nicht explizit gesetzt werden. +```yaml +apcupsd_nis_master: on +``` -##### apcupsd will shutdown the system during a power failure when the remaining runtime on batteries as internally calculated by the UPS falls below the specified minutes. -MINUTES: 10 +##### FQDN oder IP des "master" +```yaml +apcupsd_nis_master_hostname: pve2.grote.lan +``` -##### Specifies when apcupsd should create the nologon file to prevent users from logging on to the system. -NOLOGON: always +##### Interface auf dem der "Master" erreichbar ist. +```yaml +apcupsd_nis_master_listen_ip: 0.0.0.0 +``` + +##### Post auf dem der "Master" erreichbar ist. +```yaml +apcupsd_nis_master_listen_port: 3551 +``` + +##### Name der USV +```yaml +apcupsd_ups_name: APC-BX950U-GR +``` diff --git a/roles/mgrote.apcupsd/defaults/main.yml b/roles/mgrote.apcupsd/defaults/main.yml index 1c7b122b..8919ab18 100644 --- a/roles/mgrote.apcupsd/defaults/main.yml +++ b/roles/mgrote.apcupsd/defaults/main.yml @@ -1,5 +1,16 @@ --- - ONBATTERYDELAY: 10 - BATTERYLEVEL: 50 - MINUTES: 10 - NOLOGON: always + apcupsd_master_onbatterydelay: 10 + apcupsd_master_batterylevel_for_shutdown: 50 + apcupsd_master_minutes_for_shutdown: 10 + apcupsd_master_nologon_when_active: always + + apcupsd_slave_onbatterydelay: 10 + apcupsd_slave_batterylevel_for_shutdown: 60 + apcupsd_slave_minutes_for_shutdown: 11 + apcupsd_slave_nologon_when_active: always + + apcupsd_nis_master: on + apcupsd_nis_master_hostname: pve2.grote.lan + apcupsd_nis_master_listen_ip: 0.0.0.0 + apcupsd_nis_master_listen_port: 3551 + apcupsd_ups_name: APC-BX950U-GR diff --git a/roles/mgrote.apcupsd/tasks/main.yml b/roles/mgrote.apcupsd/tasks/main.yml index 03523d6e..a16f89c2 100644 --- a/roles/mgrote.apcupsd/tasks/main.yml +++ b/roles/mgrote.apcupsd/tasks/main.yml @@ -1,4 +1,5 @@ - - name: apcupsd installieren +--- + - name: install apcupsd packages ansible.builtin.package: name: - apcupsd @@ -8,13 +9,25 @@ become: yes notify: apc_access_mail - - name: apcupsd kopieren + - name: create master config + include_tasks: master.yml + when: + - apcupsd_nis_master + - apcupsd_nis_master is defined + + - name: create slave config + include_tasks: slave.yml + when: + - not apcupsd_nis_master + - apcupsd_nis_master is defined + + - name: copy apcupsd file become: yes ansible.builtin.template: src: "apcupsd" dest: "/etc/default/apcupsd" - - name: empfaenger_mail_setzen + - name: set mail recipient become: yes ansible.builtin.lineinfile: path: /etc/apcupsd/apccontrol #wo @@ -22,9 +35,8 @@ line: export SYSADMIN={{ empfaenger_mail }} #ersetze durch... backrefs: yes #verhindert das die zeile bei "nicht zutreffen" am ende der datei angefuegt wird: https://docs.ansible.com/ansible/latest/modules/lineinfile_module.html#parameters - - name: apcupsd.conf_kopieren + - name: copy test script become: yes ansible.builtin.template: - src: "apcupsd.conf" - dest: "/etc/apcupsd/apcupsd.conf" - notify: restart_apcupsd #benachrichtigt handlers/main.yml-restart-apcupsd_restart um den dient neuzustarten, nur wenn hier status "changed" ausgeworfen wird" + src: "apccontrol.save" + dest: "/etc/apcupsd/apccontrol.save" diff --git a/roles/mgrote.apcupsd/tasks/master.yml b/roles/mgrote.apcupsd/tasks/master.yml new file mode 100644 index 00000000..6f989fd3 --- /dev/null +++ b/roles/mgrote.apcupsd/tasks/master.yml @@ -0,0 +1,7 @@ +--- + - name: templating master_apcupsd.conf + become: yes + ansible.builtin.template: + src: "master_apcupsd.conf" + dest: "/etc/apcupsd/apcupsd.conf" + notify: restart_apcupsd #benachrichtigt handlers/main.yml-restart-apcupsd_restart um den dient neuzustarten, nur wenn hier status "changed" ausgeworfen wird" diff --git a/roles/mgrote.apcupsd/tasks/slave.yml b/roles/mgrote.apcupsd/tasks/slave.yml new file mode 100644 index 00000000..171c68d0 --- /dev/null +++ b/roles/mgrote.apcupsd/tasks/slave.yml @@ -0,0 +1,7 @@ +--- + - name: templating slave_apcupsd.conf + become: yes + ansible.builtin.template: + src: "slave_apcupsd.conf" + dest: "/etc/apcupsd/apcupsd.conf" + notify: restart_apcupsd #benachrichtigt handlers/main.yml-restart-apcupsd_restart um den dient neuzustarten, nur wenn hier status "changed" ausgeworfen wird" diff --git a/roles/mgrote.apcupsd/templates/apccontrol.save b/roles/mgrote.apcupsd/templates/apccontrol.save new file mode 100644 index 00000000..db48c9dd --- /dev/null +++ b/roles/mgrote.apcupsd/templates/apccontrol.save @@ -0,0 +1,137 @@ +#!@SCRIPTSHELL@ +# +# Safe apccontrol for testing. +# +# This apccontrol can be used for testing without fear +# that it will bring your system down +# @configure_input@ +# +prefix=@prefix@ +exec_prefix=@exec_prefix@ +APCUPSD=@sbindir@/apcupsd +SHUTDOWN=@SHUTDOWN@ +SCRIPTDIR=@sysconfdir@ + +# +case "$1" in + killpower) + wall <