--- - name: Deploy TWS MOTD hosts: all become: true vars: tws_org: "TheWrightServer" 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 }}" loop: - 10-help-text - 50-motd-news register: motd_scripts - name: Disable default Ubuntu MOTD noise file: path: "{{ item.stat.path }}" mode: "0644" loop: "{{ motd_scripts.results }}" when: item.stat.exists - 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