diff --git a/tasks/main.yaml b/tasks/main.yaml index be3c3f2..9240864 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -25,7 +25,6 @@ # motd - name: "motd" ansible.builtin.import_tasks: "motd.yaml" - when: "ansible_os_family == 'Debian'" tags: "motd" # cron jobs diff --git a/tasks/motd.yaml b/tasks/motd.yaml index 3647bd6..ac24724 100644 --- a/tasks/motd.yaml +++ b/tasks/motd.yaml @@ -12,6 +12,7 @@ excludes: - "10-custom-motd" register: "old_motd" + when: "ansible_os_family == 'Debian'" # remove old custom motd files - name: "motd - cleanup directory" @@ -37,3 +38,13 @@ group: "root" mode: "0755" when: 'ansible_os_family == "Debian"' + + # configure motd + - name: "motd - siempie - alpine" + ansible.builtin.template: + src: "templates/motd/alpine-motd.sh.j2" + dest: "/etc/profile.d/motd.sh" + owner: "root" + group: "root" + mode: "0755" + when: 'ansible_os_family == "Alpine"' diff --git a/templates/motd/alpine-motd.sh.j2 b/templates/motd/alpine-motd.sh.j2 new file mode 100644 index 0000000..7616106 --- /dev/null +++ b/templates/motd/alpine-motd.sh.j2 @@ -0,0 +1,23 @@ +#!/bin/sh + +# distribution information +if [ -f /etc/os-release ]; then + . /etc/os-release + linux_distribution="\033[36m$PRETTY_NAME\033[0m" +else + linux_distribution="\033[36mUnknown Linux Distribution\033[0m" +fi + +# disk usage +disk_usage=$(df -h / | awk 'NR==2 {print $3 " / " $2 " (" $5 ")"}') + +# memory usage +memory_usage=$(free -m | awk 'NR==2 {print $3 " MB / " $2 " MB (" int($3/$2*100) "%)"}') + +# display motd +echo "Welcome to $(hostname)!" +echo "" +echo -e "$linux_distribution" +echo "Disk Usage: $disk_usage" +echo "Memory Usage: $memory_usage" +echo ""