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 9210b5c..cdedd37 100644 --- a/roles/baseconfig/tasks/main.yml +++ b/roles/baseconfig/tasks/main.yml @@ -29,15 +29,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: 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/" 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) ... 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/" 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..f4a125d --- /dev/null +++ b/roles/update_motd/tasks/main.yml @@ -0,0 +1,53 @@ +--- +- 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: + 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 additional 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/baseconfig/files/update-motd.d/00-logo b/roles/update_motd/templates/00-logo old mode 100755 new mode 100644 similarity index 87% rename from roles/baseconfig/files/update-motd.d/00-logo rename to roles/update_motd/templates/00-logo index 025257f..4456160 --- a/roles/baseconfig/files/update-motd.d/00-logo +++ b/roles/update_motd/templates/00-logo @@ -1,23 +1,23 @@ #!/bin/sh -# {{ ansible_managed }} +{{ 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"` +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}'` +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) +bold="$(tput bold)" +normal="$(tput sgr0)" # Logo -cat << EOF +cat <