diff --git a/playbooks/db.yml b/playbooks/db.yml index 72a78c5..c61b3a7 100755 --- a/playbooks/db.yml +++ b/playbooks/db.yml @@ -9,6 +9,12 @@ backup_script: s3pgdump become: yes tags: [ backup ] + - role: motd + vars: + motd_watch_services_extra: + - postgresql + become: yes + tags: [ motd ] - role: postgresql vars: postgresql_global_config_options: @@ -40,6 +46,12 @@ backup_script: s3pgdump become: yes tags: [ backup ] + - role: motd + vars: + motd_watch_services_extra: + - postgresql + become: yes + tags: [ motd ] - role: postgresql vars: postgresql_hba_entries: diff --git a/playbooks/desktop.yml b/playbooks/desktop.yml index ce6bdeb..84edbd2 100755 --- a/playbooks/desktop.yml +++ b/playbooks/desktop.yml @@ -26,6 +26,9 @@ - /home/salt/.backup/ become: yes tags: [ backup ] + - role: motd + become: yes + tags: [ motd ] - role: desktop become: yes tags: [ desktop ] diff --git a/playbooks/game.yml b/playbooks/game.yml index a4a1599..33551bc 100755 --- a/playbooks/game.yml +++ b/playbooks/game.yml @@ -17,6 +17,14 @@ - /opt/minecraft/vanilla/backups become: yes tags: [ backup ] + - role: motd + vars: + motd_watch_services_extra: + - minecraft@dammit + - minecraft@valhelsia + - minecraft@vanilla + become: yes + tags: [ motd ] - role: minecraft vars: minecraft_enabled: no diff --git a/playbooks/web.yml b/playbooks/web.yml index 1e23479..794a49f 100755 --- a/playbooks/web.yml +++ b/playbooks/web.yml @@ -20,6 +20,14 @@ - /var/lib/gitea/log become: yes tags: [ backup ] + - role: motd + become: yes + vars: + motd_watch_services_extra: + - apache2 + - gitea + - php7.4-fpm + tags: [ motd ] - role: certbot vars: certbot_admin_email: rehashedsalt@cock.li diff --git a/roles/motd/defaults/main.yml b/roles/motd/defaults/main.yml new file mode 100644 index 0000000..c563e06 --- /dev/null +++ b/roles/motd/defaults/main.yml @@ -0,0 +1,24 @@ +# vim:ft=ansible: + +# Default motd files to remove from /etc/update-motd.d +motd_remove: + - 00-header + - 10-help-text + - 50-landscape-sysinfo + - 50-motd-news + - 85-fwupd + - 90-updates-available + - 91-release-upgrade + - 92-unattended-upgrades + - 95-hwe-eol + - 97-overlayroot + - 98-fsck-at-reboot + - 98-reboot-required +motd_remove_extra: [] + +# Services to monitor with our script +# Units that can't be found will be skipped +motd_watch_services: + - ansible-pull + - backup +motd_watch_services_extra: [] diff --git a/roles/motd/tasks/main.yml b/roles/motd/tasks/main.yml new file mode 100644 index 0000000..3fbe10f --- /dev/null +++ b/roles/motd/tasks/main.yml @@ -0,0 +1,7 @@ +#!/usr/bin/env ansible-playbook +# vim:ft=ansible: +- name: remove default motd items + file: state=absent path=/etc/update-motd.d/{{ item }} + loop: "{{ motd_remove + motd_remove_extra }}" +- name: template out motd script + template: src=motd.sh dest=/etc/update-motd.d/50-ansible mode=0755 diff --git a/roles/motd/templates/motd.sh b/roles/motd/templates/motd.sh new file mode 100755 index 0000000..f920638 --- /dev/null +++ b/roles/motd/templates/motd.sh @@ -0,0 +1,52 @@ +#! /bin/bash + +# motd.sh +# A basic motd script with some nice information. Designed to be extensible +# and easily configurable per-host + +# NOTE: We do not set -e here because we don't want MOTD generation to fail +# in the event that just this script fails + +# Services that we want a quick heads-up on their status +declare -a services +{% for item in (motd_watch_services + motd_watch_services_extra)|sort %} +services+=("{{ item }}") +{% endfor %} + +## Now, we actually put this info to use +# Starting with services +if [ -n "${services[*]}" ]; then + printf "\e[1mService Statuses\e[0m\n" + len=20 + for service in "${services[@]}"; do + status="\e[33mUnknown\e[0m" + systemctl status "$service" > /dev/null 2>&1 + case $? in + 0) + status="\e[1;32mRunning\e[0m" + ;; + 1|2) + status="\e[1;31mDead\e[0m" + ;; + 3) + status="\e[37mNot Running\e[0m" + ;; + 4) + continue + ;; + esac + printf " * \e[37m%-${len}.${len}s\e[0m - $status " "$service" + if systemctl is-failed --quiet "$service"; then + printf "\e[1;31m(FAILED!)\e[0m " + fi + printf "\n" + done +fi + +## And some generic system status stuff +printf "\e[1mSystem Status\e[0m\n" +if [ -f /var/run/reboot-required ]; then + printf " * \e[1;33mReboot required\e[0m\n" +else + printf "\e[37m - No outstanding reboots\e[0m\n" +fi