Add a shitty motd

This commit is contained in:
Salt 2021-01-17 00:53:48 -06:00
parent 49b156c5dc
commit cf51bbd83c
7 changed files with 114 additions and 0 deletions

View File

@ -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:

View File

@ -26,6 +26,9 @@
- /home/salt/.backup/
become: yes
tags: [ backup ]
- role: motd
become: yes
tags: [ motd ]
- role: desktop
become: yes
tags: [ desktop ]

View File

@ -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

View File

@ -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

View File

@ -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: []

View File

@ -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

52
roles/motd/templates/motd.sh Executable file
View File

@ -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