change to script user: smart (#252)

Co-authored-by: Michael Grote <michael.grote@posteo.de>
Reviewed-on: mg/ansible#252
Co-authored-by: mg <michael.grote@posteo.de>
Co-committed-by: mg <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2021-11-23 21:51:18 +01:00
parent a730c3f6db
commit d2c425f014
9 changed files with 64 additions and 108 deletions

View file

@ -3,10 +3,6 @@
apt_packages_extra: apt_packages_extra:
- ifupdown2 - ifupdown2
- bmon - bmon
### mgrote.smart
smart_smartctlmail_cron_minutes: "15"
smart_smartctlmail_cron_hours: "6"
smart_smartctlmail_cron_weekday: "3"
### geerlingguy.munin-node ### geerlingguy.munin-node
munin_node_disabled_plugins: munin_node_disabled_plugins:
- name: meminfo # zu hohe last - name: meminfo # zu hohe last

View file

@ -1,52 +0,0 @@
---
- hosts: proxmox
become: yes
tasks:
- name: smartmontools kopieren
become: yes
ansible.builtin.file:
path: "/etc/default/smartmontools"
state: absent
- name: smartd.conf kopieren
become: yes
ansible.builtin.file:
path: "/etc/smartd.conf"
state: absent
- name: smartctl_mail.sh kopieren
become: yes
ansible.builtin.file:
path: "/usr/local/bin/smartctl_mail.sh"
state: absent
- name: smart_status.sh kopieren
become: yes
ansible.builtin.file:
path: "/usr/local/bin/smart_status.sh"
state: absent
# smartctl output als mail
- name: cronjob fuer smartctl-mail
become: yes
ansible.builtin.cron:
name: smart-mail
state: absent
job: "/usr/local/bin/smartctl_mail.sh"
minute: "{{ smart_smartctlmail_cron_minutes }}"
hour: "{{ smart_smartctlmail_cron_hours }}"
weekday: "{{ smart_smartctlmail_cron_weekday }}"
- name: smartctl_mail.sh kopieren
become: yes
ansible.builtin.file:
path: "/root/smart/smartctl_mail.sh"
state: absent
- name: smartctl_mail.sh kopieren
become: yes
ansible.builtin.file:
path: "/root/smart/"
state: absent

View file

@ -1,22 +1,30 @@
## mgrote.smart ## mgrote.smart
### Beschreibung ### Beschreibung
Installiert und konfiguriert smartmontools + Mail-Benachrichtigungen. Installiert und konfiguriert smartmontools + Mail-Benachrichtigungen.(Mail muss extra konfiguriert werden.)
Es laesst sich konfigurieren wann die kompletten SMART-Werte versendet werden.
Stellt `smart_status.sh` bereit.
Ausgabe:
```shell
mg@pve2 ~
> sudo smart_status.sh
Device Model: SAMSUNG MZ7LH960HAJR-00005
SMART test result: PASSED
Device Model: SAMSUNG MZ7LH960HAJR-00005
SMART test result: PASSED
Device Model: WDC WD80EZAZ-11TDBA0
SMART test result: PASSED
Device Model: WDC WD80EZAZ-11TDBA0
SMART test result: PASSED
Device Model: WDC WD80EZAZ-11TDBA0
SMART test result: PASSED
Device Model: MTFDDAK256MBF-1AN15ABHA
SMART test result: PASSED
```
### getestet auf ### getestet auf
- [ ] Ubuntu (>=18.04) - [x] ProxMox 6*
- [ ] Debian - [x] ProxMox 7*
- [x] ProxMox 6.1
### Variablen + Defaults ### Variablen + Defaults
##### Wer soll die Mail bekommen - see [defaults](./defaults/main.yml)
``empfaenger_mail: michael.grote@posteo.de``
##### Wann sollen die SMART-Werte verschickt werden.(Minuten)
``smart_smartctlmail_cron_minutes``
##### Wann sollen die SMART-Werte verschickt werden.(Stunden)
``smart_smartctlmail_cron_hours``
##### Wann sollen die SMART-Werte verschickt werden.(Wochentag)
``smart_smartctlmail_cron_weekday``
##### Pfad zu smartctl
``smart_smartctl_mail_pfad_smartctl: "/usr/sbin/smartctl"``

View file

@ -1,5 +1,6 @@
--- ---
smart_smartctlmail_cron_minutes: 15 # path to smartctl
smart_smartctlmail_cron_hours: 6 smart_smartctl_path: "/usr/sbin/smartctl"
smart_smartctlmail_cron_weekday: 3 # under which user the script is run
smart_smartctl_mail_pfad_smartctl: "/usr/sbin/smartctl" smart_user_group: "root"
smart_user: "smart"

View file

@ -1,5 +1,5 @@
--- ---
- name: smartmontools_starten_aktivieren - name: restart smartmontools
become: yes become: yes
systemd: systemd:
name: smartmontools name: smartmontools

View file

@ -1,46 +1,36 @@
--- ---
#Blockdevice/Festplatten muessen haendisch in "templates" eingetragen werden - name: include user tasks
- name: smartmontools installieren include_tasks: user.yml
- name: ensure smartmontools are installed
become: yes become: yes
ansible.builtin.package: ansible.builtin.package:
name: smartmontools name: smartmontools
state: present state: present
- name: smartmontools kopieren - name: template smartmontools config
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
src: "smartmontools" src: "smartmontools"
dest: "/etc/default/smartmontools" dest: "/etc/default/smartmontools"
notify: smartmontools_starten_aktivieren owner: "{{ smart_user }}"
group: "{{ smart_user_group }}"
notify: restart smartmontools
- name: smartd.conf kopieren - name: template smartd.conf
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
src: "smartd.conf" src: "smartd.conf"
dest: "/etc/smartd.conf" dest: "/etc/smartd.conf"
notify: smartmontools_starten_aktivieren owner: "{{ smart_user }}"
group: "{{ smart_user_group }}"
notify: restart smartmontools
- name: smartctl_mail.sh kopieren - name: copy smart_status.sh
become: yes
ansible.builtin.template:
src: "smartctl_mail.sh"
dest: "/usr/local/bin/smartctl_mail.sh"
mode: a+x
- name: smart_status.sh kopieren
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
src: "smart_status.sh" src: "smart_status.sh"
dest: "/usr/local/bin/smart_status.sh" dest: "/usr/local/bin/smart_status.sh"
mode: a+x owner: "{{ smart_user }}"
group: "{{ smart_user_group }}"
# smartctl output als mail mode: 0744
- name: cronjob fuer smartctl-mail
become: yes
ansible.builtin.cron:
name: smart-mail
state: present
job: "/usr/local/bin/smartctl_mail.sh"
minute: "{{ smart_smartctlmail_cron_minutes }}"
hour: "{{ smart_smartctlmail_cron_hours }}"
weekday: "{{ smart_smartctlmail_cron_weekday }}"

View file

@ -0,0 +1,18 @@
---
- name: ensure group exists
become: true
ansible.builtin.group:
name: "{{ smart_user_group }}"
state: present
when:
- smart_user_group is defined
- name: ensure user exists
become: true
ansible.builtin.user:
name: "{{ smart_user }}"
group: "{{ smart_user_group }}"
shell: /usr/sbin/nologin
when:
- smart_user_group is defined
- smart_user is defined

View file

@ -1,5 +0,0 @@
#!/bin/bash
{{ file_header | default () }}
for i in {a..z}; do
{{ smart_smartctl_mail_pfad_smartctl }} /dev/sd$i -a
done

View file

@ -1,3 +1,3 @@
enable_smart="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn /dev/sdo /dev/sdp" enable_smart="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn /dev/sdo /dev/sdp /dev/sdq /dev/sdr /dev/sds /dev/sdt /dev/sdu /dev/sdw /dev/sdv /dev/sdx /dev/sdy /dev/sdz"
start_smartd=yes start_smartd=yes
smartd_opts="--interval=14400" smartd_opts="--interval=14400"