Update deploy-tws-motd

This commit is contained in:
2026-01-19 20:49:36 -05:00
parent 33463dcd31
commit 3f17822ca6

View File

@@ -8,6 +8,17 @@
tws_short: "TWS"
tasks:
- name: Remove static MOTD file (Debian default)
file:
path: /etc/motd
state: absent
- name: Ensure dynamic MOTD symlink
file:
src: /run/motd.dynamic
dest: /etc/motd
state: link
- name: Check for default Ubuntu MOTD scripts
stat:
path: "/etc/update-motd.d/{{ item }}"
@@ -29,35 +40,49 @@
mode: "0755"
content: |
#!/bin/bash
ORG="{{ tws_org }}"
SHORT="{{ tws_short }}"
HOSTNAME="$(hostname)"
WIDTH=58
line() {
printf "║ %-*s ║\n" $((WIDTH-4)) "$1"
}
border_top() {
printf "╔%s╗\n" "$(printf '═%.0s' $(seq 1 $((WIDTH-2))))"
}
border_mid() {
printf "╠%s╣\n" "$(printf '═%.0s' $(seq 1 $((WIDTH-2))))"
}
border_bot() {
printf "╚%s╝\n" "$(printf '═%.0s' $(seq 1 $((WIDTH-2))))"
}
HOST="$(hostname)"
OS="$(lsb_release -ds 2>/dev/null || grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '"')"
KERNEL="$(uname -r)"
IP="$(hostname -I | awk '{print $1}')"
UPTIME="$(uptime -p | sed 's/up //')"
LOAD="$(awk '{print $1}' /proc/loadavg)"
MEM_USED="$(free -h | awk '/Mem:/ {print $3}')"
MEM_TOTAL="$(free -h | awk '/Mem:/ {print $2}')"
DISK_USED="$(df -h / | awk 'NR==2 {print $5}')"
MEM="$(free -h | awk '/Mem:/ {print $3 " / " $2}')"
DISK="$(df -h / | awk 'NR==2 {print $5 " used (/)"}')"
USERS="$(who | wc -l)"
cat <<EOF
╔══════════════════════════════════════════════════════════╗
║ ${ORG} • ${SHORT} Infrastructure
╠══════════════════════════════════════════════════════════╣
║ Host : ${HOSTNAME}
║ OS : ${OS}
║ Kernel : ${KERNEL}
║ IP : ${IP}
║ Uptime : ${UPTIME}
╠══════════════════════════════════════════════════════════╣
║ CPU Load : ${LOAD}
║ Memory : ${MEM_USED} / ${MEM_TOTAL}
║ Disk : ${DISK_USED} used (/)
║ Users : ${USERS} logged in
╚══════════════════════════════════════════════════════════╝
EOF
border_top
line "${ORG} • ${SHORT} Infrastructure"
border_mid
line "Host : ${HOST}"
line "OS : ${OS}"
line "Kernel : ${KERNEL}"
line "IP : ${IP}"
line "Uptime : ${UPTIME}"
border_mid
line "CPU Load : ${LOAD}"
line "Memory : ${MEM}"
line "Disk : ${DISK}"
line "Users : ${USERS} logged in"
border_bot