From 7e92fdfab7079993b0c2db41cfee60a0c5926998 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 6 Mar 2021 04:30:32 +0100 Subject: [PATCH 1/7] 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 < Date: Sat, 6 Mar 2021 04:31:20 +0100 Subject: [PATCH 2/7] Use 'update_motd' in 'baseconfig' --- roles/baseconfig/files/update-motd.d/00-logo | 39 ------------------- roles/baseconfig/files/update-motd.d/10-uname | 3 -- roles/baseconfig/tasks/main.yml | 11 +----- 3 files changed, 2 insertions(+), 51 deletions(-) delete mode 100755 roles/baseconfig/files/update-motd.d/00-logo delete mode 100755 roles/baseconfig/files/update-motd.d/10-uname diff --git a/roles/baseconfig/files/update-motd.d/00-logo b/roles/baseconfig/files/update-motd.d/00-logo deleted file mode 100755 index 025257f..0000000 --- a/roles/baseconfig/files/update-motd.d/00-logo +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh -# {{ ansible_managed }} - -# 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 << EOF - -      ${bold}Uptime${normal} : ${UPTIME} -    ${bold}Mémoire${normal} : ${RAM} -        ${bold}Disque racine${normal} : ${DISK} -        -           -            -           -           -        -        -          -          -          -            -         -   ${bold}Aurore${normal}     - -EOF diff --git a/roles/baseconfig/files/update-motd.d/10-uname b/roles/baseconfig/files/update-motd.d/10-uname deleted file mode 100755 index 4586095..0000000 --- a/roles/baseconfig/files/update-motd.d/10-uname +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -# {{ ansible_managed }} -uname -snrvm diff --git a/roles/baseconfig/tasks/main.yml b/roles/baseconfig/tasks/main.yml index 0c13978..04492c3 100644 --- a/roles/baseconfig/tasks/main.yml +++ b/roles/baseconfig/tasks/main.yml @@ -32,15 +32,8 @@ retries: 3 until: apt_result is succeeded -# Pimp my server -- name: Customize motd - copy: - src: "update-motd.d/{{ item }}" - dest: "/etc/update-motd.d/{{ item }}" - mode: 0755 - loop: - - 00-logo - - 10-uname +- include_role: + name: update_motd - name: Remove Debian warranty motd file: From 1d0200a1f050e6068cd1cdd55f9ab0bb366890f3 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 6 Mar 2021 04:32:06 +0100 Subject: [PATCH 3/7] Use 'update_motd' in 'prometheus' --- roles/prometheus/tasks/main.yml | 13 ++++++++----- .../templates/update-motd.d/05-service.j2 | 4 ---- 2 files changed, 8 insertions(+), 9 deletions(-) delete mode 100755 roles/prometheus/templates/update-motd.d/05-service.j2 diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml index a820190..a3d2063 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -84,8 +84,11 @@ enabled: true state: started -- name: Indicate role in motd - template: - src: update-motd.d/05-service.j2 - dest: /etc/update-motd.d/05-prometheus - mode: 0755 +- include_role: + name: update_motd + vars: + motd_messages: + - key: 05-prometheus + message: >- + Prometheus est déployé sur cette machine (voir /etc/prometheus) +... diff --git a/roles/prometheus/templates/update-motd.d/05-service.j2 b/roles/prometheus/templates/update-motd.d/05-service.j2 deleted file mode 100755 index f027dc4..0000000 --- a/roles/prometheus/templates/update-motd.d/05-service.j2 +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# {{ ansible_managed }} -echo "> prometheus a été déployé sur cette machine." -echo " Voir /etc/prometheus/" From 2353589da6e79906692159cc313ad73c1ddca1f1 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 6 Mar 2021 04:42:21 +0100 Subject: [PATCH 4/7] Ensures /etc/update-motd.d exists --- roles/update_motd/tasks/main.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/roles/update_motd/tasks/main.yml b/roles/update_motd/tasks/main.yml index ce90dfa..edfda74 100644 --- a/roles/update_motd/tasks/main.yml +++ b/roles/update_motd/tasks/main.yml @@ -1,4 +1,13 @@ --- +- name: Ensure update-motd.d exists + become: true + file: + path: /etc/update-motd.d + state: directory + mode: u=rwx,g=rx,o=rx + owner: root + group: root + - name: Customize motd become: true template: From bc2701d8ba957b1a29d8a87a80cb1c86b2f60c5f Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 6 Mar 2021 04:43:09 +0100 Subject: [PATCH 5/7] Use 'update_motd' in 'prometheus_federate' --- .../prometheus_federate/templates/update-motd.d/05-service.j2 | 4 ---- 1 file changed, 4 deletions(-) delete mode 100755 roles/prometheus_federate/templates/update-motd.d/05-service.j2 diff --git a/roles/prometheus_federate/templates/update-motd.d/05-service.j2 b/roles/prometheus_federate/templates/update-motd.d/05-service.j2 deleted file mode 100755 index f027dc4..0000000 --- a/roles/prometheus_federate/templates/update-motd.d/05-service.j2 +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# {{ ansible_managed }} -echo "> prometheus a été déployé sur cette machine." -echo " Voir /etc/prometheus/" From 71ee06c9c086758d4d514e9658990c15f1a9c002 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 6 Mar 2021 04:45:00 +0100 Subject: [PATCH 6/7] Fix typo --- roles/update_motd/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/update_motd/tasks/main.yml b/roles/update_motd/tasks/main.yml index edfda74..f4a125d 100644 --- a/roles/update_motd/tasks/main.yml +++ b/roles/update_motd/tasks/main.yml @@ -39,7 +39,7 @@ group: root notify: Remove cached motd -- name: Install additionnal motd messages +- name: Install additional motd messages become: true copy: content: "✨ {{ item.message }}\n" From 929baa300f2888fc0daa594b54838c2a9d234b5c Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sat, 6 Mar 2021 04:48:39 +0100 Subject: [PATCH 7/7] Use 'update_motd' in 'prometheus_federate' (again) --- roles/prometheus_federate/tasks/main.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/prometheus_federate/tasks/main.yml b/roles/prometheus_federate/tasks/main.yml index f168f1f..73ae803 100644 --- a/roles/prometheus_federate/tasks/main.yml +++ b/roles/prometheus_federate/tasks/main.yml @@ -38,9 +38,12 @@ enabled: true state: started -- name: Indicate role in motd - template: - src: update-motd.d/05-service.j2 - dest: /etc/update-motd.d/05-prometheus - mode: 0755 +- include_role: + name: update_motd + vars: + motd_messages: + - key: 05-prometheus-federate + message: >- + Prometheus (en configuration fédération) est déployé sur cette + machine (voir /etc/prometheus) ...