diff --git a/ansible/playbooks/lab.yaml b/ansible/playbooks/lab.yaml index 15f109a..196c96d 100644 --- a/ansible/playbooks/lab.yaml +++ b/ansible/playbooks/lab.yaml @@ -9,5 +9,7 @@ - sshd - firewall - pikaur + - msmtp - zfs-install - - libvirt-server \ No newline at end of file + - libvirt-server + \ No newline at end of file diff --git a/ansible/roles/msmtp/tasks/main.yml b/ansible/roles/msmtp/tasks/main.yml new file mode 100644 index 0000000..50b9c46 --- /dev/null +++ b/ansible/roles/msmtp/tasks/main.yml @@ -0,0 +1,10 @@ +--- +#TODO install packages +# msmtp +# msmtp-mta +# s-nail + +#TODO add folder /var/log/msmtp + +#TODO add template file msmtprc.j2 to /etc/msmtprc +#TODO add template file aliases.j2 to /etc/aliases \ No newline at end of file diff --git a/ansible/roles/msmtp/templates/aliases.j2 b/ansible/roles/msmtp/templates/aliases.j2 new file mode 100644 index 0000000..0e6721c --- /dev/null +++ b/ansible/roles/msmtp/templates/aliases.j2 @@ -0,0 +1 @@ +root: {{ smtp_admin }} diff --git a/ansible/roles/msmtp/templates/msmtprc.j2 b/ansible/roles/msmtp/templates/msmtprc.j2 new file mode 100644 index 0000000..bd334be --- /dev/null +++ b/ansible/roles/msmtp/templates/msmtprc.j2 @@ -0,0 +1,19 @@ +# Set default values for all following accounts. +defaults +aliases /etc/aliases +auth on +tls on +tls_trust_file /etc/ssl/certs/ca-certificates.crt +logfile /var/log/msmtp/msmtp.log + +# Home +account main +host {{ smtp_host }} +port {{ smtp_port }} +from {{ smtp_user }} +user {{ smtp_user }} +password {{ smtp_password }} +tls_starttls {{ smtp_start_tls }} + +# Set a default account +account default : main diff --git a/ansible/roles/zfs-install/defaults/main.yml b/ansible/roles/zfs-install/defaults/main.yml index 6ca30c8..94bf561 100644 --- a/ansible/roles/zfs-install/defaults/main.yml +++ b/ansible/roles/zfs-install/defaults/main.yml @@ -7,6 +7,7 @@ zfs_packages: - zfs-utils - zfs-dkms - mbuffer + - smartmontools zfs_arc_min: '1073741824' zfs_arc_max: '4294967296' zfs_zpool_ashift: '12' diff --git a/ansible/roles/zfs-install/tasks/main.yml b/ansible/roles/zfs-install/tasks/main.yml index 949e2f7..d9dee23 100644 --- a/ansible/roles/zfs-install/tasks/main.yml +++ b/ansible/roles/zfs-install/tasks/main.yml @@ -155,4 +155,18 @@ - mount - receive - rollback - - recordsize \ No newline at end of file + - recordsize + +# Adjust offset from 1H to 1D in zfs-scrub-monthly@{{ zfs-pool }}.timer + +# TODO enable/start zfs-scrub-monthly@{{ zfs-pool }}.timer + +# TODO configure /etc/zfs/zed.d/zed.rc + +# TODO enable/start zfs-zed.service + +# TODO possible configure /etc/conf.d/smartdargs + +# TODO configure /etc/smartd.conf + +# TODO enable/start smartd.service \ No newline at end of file diff --git a/ansible/roles/zfs-install/templates/smartd.conf.j2 b/ansible/roles/zfs-install/templates/smartd.conf.j2 new file mode 100644 index 0000000..50d7824 --- /dev/null +++ b/ansible/roles/zfs-install/templates/smartd.conf.j2 @@ -0,0 +1 @@ +DEVICESCAN -a -o on -S on -s (S/../.././03|L/../01/./04) -W 4,45,60 -m notificationrecipient@emailprovider.com -M exec /usr/local/bin/smartdnotify.sh \ No newline at end of file diff --git a/ansible/roles/zfs-install/templates/smartdnotify.sh.j2 b/ansible/roles/zfs-install/templates/smartdnotify.sh.j2 new file mode 100644 index 0000000..2a73d64 --- /dev/null +++ b/ansible/roles/zfs-install/templates/smartdnotify.sh.j2 @@ -0,0 +1,27 @@ +#! /bin/bash + +# Create a file to store the message in. Give it a unique filename to avoid issues if this script runs twice simultaneously +msgFile="/root/$(uuidgen).txt" + +# Clear file, set subject line and formatting +echo "Subject: $SMARTD_SUBJECT" > $msgFile +echo "Content-Type: text/html" >> $msgFile +echo "" >> $msgFile +echo "" >> $msgFile +echo "" >> $msgFile +echo "
" >> $msgFile
+
+# Save the email message from STDIN:
+cat >> $msgFile
+
+# Append the output of zpool status:
+/usr/sbin/zpool status >> $msgFile
+
+# Append the output of smartctl -a to the message:
+/usr/sbin/smartctl -a "$SMARTD_DEVICE" >> $msgFile
+
+# Close HTML tags
+echo "
" >> $msgFile + +# Now email the message to the user at address ADD: +/bin/msmtp "$SMARTD_ADDRESS" < $msgFile \ No newline at end of file