From 2b45ea7dcff932173dc9da3eb4d74fadf0969e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Camacho?= Date: Mon, 16 Feb 2026 14:11:50 +0100 Subject: [PATCH] add roles --- roles/base/tasks/main.yml | 12 ++++++ roles/base/tasks/motd.yml | 32 +++++++++++++++ roles/base/tasks/system.yml | 0 roles/base/templates/99-template-homelab.j2 | 44 +++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 roles/base/tasks/main.yml create mode 100644 roles/base/tasks/motd.yml create mode 100644 roles/base/tasks/system.yml create mode 100644 roles/base/templates/99-template-homelab.j2 diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml new file mode 100644 index 0000000..bb6c237 --- /dev/null +++ b/roles/base/tasks/main.yml @@ -0,0 +1,12 @@ +--- +- name: Load default vars for role + ansible.builtin.include_vars: + file: vars/default.yml + +- name: Setup config system + ansible.builtin.import_tasks: system.yml + tags: [system] + +- name: Configure MOTD + ansible.builtin.import_tasks: motd.yml + tags: [motd] diff --git a/roles/base/tasks/motd.yml b/roles/base/tasks/motd.yml new file mode 100644 index 0000000..3e96dfc --- /dev/null +++ b/roles/base/tasks/motd.yml @@ -0,0 +1,32 @@ +--- +- name: Ensure update-motd directory exists + ansible.builtin.file: + path: /etc/update-motd.d + state: directory + mode: "0755" + +- name: Remove static Debian motd + ansible.builtin.copy: + dest: /etc/motd + content: "" + force: true + +- name: Disable default Debian MOTD scripts if present + ansible.builtin.file: + path: "{{ item }}" + mode: "0644" + loop: + - /etc/update-motd.d/10-uname + - /etc/update-motd.d/10-help-text + ignore_errors: true + +- name: Remove legacy profile.d MOTD if exists + ansible.builtin.file: + path: /etc/profile.d/00_lxc-details.sh + state: absent + +- name: Install custom homelab MOTD + ansible.builtin.template: + src: 99-homelab.j2 + dest: /etc/update-motd.d/99-homelab + mode: "0755" diff --git a/roles/base/tasks/system.yml b/roles/base/tasks/system.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/base/templates/99-template-homelab.j2 b/roles/base/templates/99-template-homelab.j2 new file mode 100644 index 0000000..3c6efe9 --- /dev/null +++ b/roles/base/templates/99-template-homelab.j2 @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +BOLD="\033[1m" +DIM="\033[2m" +GREEN="\033[1;32m" +BLUE="\033[1;34m" +CYAN="\033[1;36m" +YELLOW="\033[1;33m" +RESET="\033[0m" + +HOST="$(hostname)" +IP="$(hostname -I | awk '{print $1}')" +OS="$(grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '"')" +KERNEL="$(uname -r)" +UPTIME="$(uptime -p)" +LOAD="$(cut -d ' ' -f1-3 /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 $3}')" +DISK_TOTAL="$(df -h / | awk 'NR==2 {print $2}')" +DISK_PERC="$(df -h / | awk 'NR==2 {print $5}')" + +UPDATES="$(apt list --upgradable 2>/dev/null | grep -c upgradable || true)" + +echo "" +echo -e "${BOLD}${BLUE}┌──────────────────────────────────────────────┐${RESET}" +echo -e "${BOLD}${BLUE}│ {{ motd_title | default('LXC CONTAINER') }} │${RESET}" +echo -e "${BOLD}${BLUE}└──────────────────────────────────────────────┘${RESET}" +echo "" + +echo -e " ${CYAN}Host:${RESET} ${BOLD}$HOST${RESET}" +echo -e " ${CYAN}IP:${RESET} $IP" +echo -e " ${CYAN}OS:${RESET} $OS" +echo -e " ${CYAN}Kernel:${RESET} $KERNEL" + +echo "" +echo -e " ${YELLOW}Uptime:${RESET} $UPTIME" +echo -e " ${YELLOW}Load:${RESET} $LOAD" + +echo "" +echo -e " ${GREEN}Memory:${RESET} $MEM_USED / $MEM_TOTAL" +echo -e " ${GREEN}Disk /:${RESET} $DISK_USED / $DISK_TOTAL (${DISK_PERC})" \ No newline at end of file