Rôle pour motd #38
11 changed files with 99 additions and 40 deletions
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# {{ ansible_managed }}
|
|
||||||
uname -snrvm
|
|
|
@ -32,15 +32,8 @@
|
||||||
retries: 3
|
retries: 3
|
||||||
until: apt_result is succeeded
|
until: apt_result is succeeded
|
||||||
|
|
||||||
# Pimp my server
|
- include_role:
|
||||||
- name: Customize motd
|
name: update_motd
|
||||||
copy:
|
|
||||||
src: "update-motd.d/{{ item }}"
|
|
||||||
dest: "/etc/update-motd.d/{{ item }}"
|
|
||||||
mode: 0755
|
|
||||||
loop:
|
|
||||||
- 00-logo
|
|
||||||
- 10-uname
|
|
||||||
|
|
||||||
- name: Remove Debian warranty motd
|
- name: Remove Debian warranty motd
|
||||||
file:
|
file:
|
||||||
|
|
|
@ -84,8 +84,11 @@
|
||||||
enabled: true
|
enabled: true
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Indicate role in motd
|
- include_role:
|
||||||
template:
|
name: update_motd
|
||||||
src: update-motd.d/05-service.j2
|
vars:
|
||||||
dest: /etc/update-motd.d/05-prometheus
|
motd_messages:
|
||||||
mode: 0755
|
- key: 05-prometheus
|
||||||
|
message: >-
|
||||||
|
Prometheus est déployé sur cette machine (voir /etc/prometheus)
|
||||||
|
...
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# {{ ansible_managed }}
|
|
||||||
echo "> prometheus a été déployé sur cette machine."
|
|
||||||
echo " Voir /etc/prometheus/"
|
|
|
@ -38,9 +38,12 @@
|
||||||
enabled: true
|
enabled: true
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Indicate role in motd
|
- include_role:
|
||||||
template:
|
name: update_motd
|
||||||
src: update-motd.d/05-service.j2
|
vars:
|
||||||
dest: /etc/update-motd.d/05-prometheus
|
motd_messages:
|
||||||
mode: 0755
|
- key: 05-prometheus-federate
|
||||||
|
message: >-
|
||||||
|
Prometheus (en configuration fédération) est déployé sur cette
|
||||||
|
machine (voir /etc/prometheus)
|
||||||
...
|
...
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# {{ ansible_managed }}
|
|
||||||
echo "> prometheus a été déployé sur cette machine."
|
|
||||||
echo " Voir /etc/prometheus/"
|
|
10
roles/update_motd/handlers/main.yml
Normal file
10
roles/update_motd/handlers/main.yml
Normal file
|
@ -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
|
||||||
|
...
|
53
roles/update_motd/tasks/main.yml
Normal file
53
roles/update_motd/tasks/main.yml
Normal file
|
@ -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
|
||||||
|
...
|
18
roles/baseconfig/files/update-motd.d/00-logo → roles/update_motd/templates/00-logo
Executable file → Normal file
18
roles/baseconfig/files/update-motd.d/00-logo → roles/update_motd/templates/00-logo
Executable file → Normal file
|
@ -1,20 +1,20 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# {{ ansible_managed }}
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
# Pretty uptime
|
# Pretty uptime
|
||||||
upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
|
upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
|
||||||
mins=$((${upSeconds}/60%60))
|
mins="$((upSeconds / 60 % 60))"
|
||||||
hours=$((${upSeconds}/3600%24))
|
hours="$((upSeconds / 3600 % 24))"
|
||||||
days=$((${upSeconds}/86400))
|
days="$((upSeconds / 86400))"
|
||||||
UPTIME=`printf "%d jours, %02dh%02dm" "$days" "$hours" "$mins"`
|
UPTIME="$(printf "%d jours, %02dh%02dm" "$days" "$hours" "$mins")"
|
||||||
|
|
||||||
# RAM
|
# RAM
|
||||||
RAM=`free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'`
|
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}'`
|
DISK="$(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}')"
|
||||||
|
|
||||||
# Text font
|
# Text font
|
||||||
bold=$(tput bold)
|
bold="$(tput bold)"
|
||||||
normal=$(tput sgr0)
|
normal="$(tput sgr0)"
|
||||||
|
|
||||||
# Logo
|
# Logo
|
||||||
cat <<EOF
|
cat <<EOF
|
4
roles/update_motd/templates/10-messages
Normal file
4
roles/update_motd/templates/10-messages
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -euf
|
||||||
|
|
||||||
|
find /etc/motd-messages -type f -exec cat -- {} +
|
4
roles/update_motd/templates/20-uname
Normal file
4
roles/update_motd/templates/20-uname
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
|
uname -snrvm
|
Loading…
Reference in a new issue