From 7e92fdfab7079993b0c2db41cfee60a0c5926998 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 6 Mar 2021 04:30:32 +0100 Subject: [PATCH] Create an 'update_motd' role --- roles/update_motd/handlers/main.yml | 10 ++++++ roles/update_motd/tasks/main.yml | 44 +++++++++++++++++++++++++ roles/update_motd/templates/00-logo | 39 ++++++++++++++++++++++ roles/update_motd/templates/10-messages | 4 +++ roles/update_motd/templates/20-uname | 4 +++ 5 files changed, 101 insertions(+) create mode 100644 roles/update_motd/handlers/main.yml create mode 100644 roles/update_motd/tasks/main.yml create mode 100644 roles/update_motd/templates/00-logo create mode 100644 roles/update_motd/templates/10-messages create mode 100644 roles/update_motd/templates/20-uname diff --git a/roles/update_motd/handlers/main.yml b/roles/update_motd/handlers/main.yml new file mode 100644 index 0000000..41dcc84 --- /dev/null +++ b/roles/update_motd/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Remove cached motd + become: true + file: + path: "{{ item }}" + state: absent + loop: + - /var/run/motd.dynamic + - /var/run/motd.dynamic.new +... diff --git a/roles/update_motd/tasks/main.yml b/roles/update_motd/tasks/main.yml new file mode 100644 index 0000000..ce90dfa --- /dev/null +++ b/roles/update_motd/tasks/main.yml @@ -0,0 +1,44 @@ +--- +- name: Customize motd + become: true + template: + src: "{{ item }}" + dest: "/etc/update-motd.d/{{ item }}" + mode: u=rwx,g=rx,o=rx + owner: root + group: root + loop: + - 00-logo + - 10-messages + - 20-uname + notify: Remove cached motd + +- name: Remove Debian warranty motd + become: true + file: + path: /etc/motd + state: absent + notify: Remove cached motd + +- name: Ensure motd-messages exists + become: true + file: + path: /etc/motd-messages + state: directory + mode: u=rwx,g=rx,o=rx + owner: root + group: root + notify: Remove cached motd + +- name: Install additionnal motd messages + become: true + copy: + content: "✨ {{ item.message }}\n" + dest: "/etc/motd-messages/{{ item.key }}" + mode: u=rwx,g=rx,o=rx + owner: root + group: root + loop: "{{ motd_messages }}" + notify: Remove cached motd + when: motd_messages is defined +... diff --git a/roles/update_motd/templates/00-logo b/roles/update_motd/templates/00-logo new file mode 100644 index 0000000..4456160 --- /dev/null +++ b/roles/update_motd/templates/00-logo @@ -0,0 +1,39 @@ +#!/bin/sh +{{ ansible_managed | comment }} + +# Pretty uptime +upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" +mins="$((upSeconds / 60 % 60))" +hours="$((upSeconds / 3600 % 24))" +days="$((upSeconds / 86400))" +UPTIME="$(printf "%d jours, %02dh%02dm" "$days" "$hours" "$mins")" + +# RAM +RAM="$(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2}')" +DISK="$(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}')" + +# Text font +bold="$(tput bold)" +normal="$(tput sgr0)" + +# Logo +cat <