--- - name: Deploy TWS MOTD (authoritative) hosts: all become: true vars: tws_org: "TheWrightServer" tws_short: "TWS" tasks: # ---------------------------- # MOTD PIPELINE SANITIZATION # ---------------------------- - name: Remove static Debian MOTD file: path: /etc/motd state: absent - name: Ensure dynamic MOTD symlink file: src: /run/motd.dynamic dest: /etc/motd state: link - name: Disable Proxmox profile banner file: path: /etc/profile.d/pve.sh state: absent ignore_errors: true # Debian runs pam_motd twice — we disable the login path - name: Disable pam_motd in login (prevents duplicate MOTD) replace: path: /etc/pam.d/login regexp: '^(session\s+optional\s+pam_motd.so.*)$' replace: '# \1' ignore_errors: true # ---------------------------- # DISABLE DEFAULT MOTD SCRIPTS # ---------------------------- - name: Find default MOTD scripts find: paths: /etc/update-motd.d file_type: file patterns: - "10-help-text" - "50-motd-news" register: motd_noise - name: Disable default MOTD noise file: path: "{{ item.path }}" mode: "0644" loop: "{{ motd_noise.files }}" # ---------------------------- # DEPLOY TWS MOTD # ---------------------------- - name: Deploy TWS MOTD script copy: dest: /etc/update-motd.d/10-tws mode: "0755" content: | #!/bin/bash ORG="{{ tws_org }}" SHORT="{{ tws_short }}" 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="$(free -h | awk '/Mem:/ {print $3 " / " $2}')" DISK="$(df -h / | awk 'NR==2 {print $5 " used (/)"}')" USERS="$(who | wc -l)" 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