add roles

This commit is contained in:
Jesús Camacho 2026-02-16 14:11:50 +01:00
parent f099e9eb9f
commit 2b45ea7dcf
4 changed files with 88 additions and 0 deletions

12
roles/base/tasks/main.yml Normal file
View file

@ -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]

32
roles/base/tasks/motd.yml Normal file
View file

@ -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"

View file

View file

@ -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})"