From d422d04bd4e51d479d2ff2234def5c6512784f0a Mon Sep 17 00:00:00 2001
From: Alexandre Iooss <erdnaxe@crans.org>
Date: Mon, 8 Jul 2019 17:45:19 +0200
Subject: [PATCH] Restructure README and motd indications

---
 README.md                                     | 91 +++++++++----------
 monitoring.yml                                | 12 ---
 network.yml                                   | 12 ---
 roles/framadate/tasks/main.yml                |  6 ++
 .../templates/update-motd.d/05-service.j2     |  3 +
 roles/grafana/tasks/main.yml                  |  6 ++
 .../templates/update-motd.d/05-service.j2     |  3 +
 roles/motd-role/tasks/main.yml                |  6 --
 .../templates/update-motd.d/05-service.j2     |  6 --
 roles/prometheus/tasks/main.yml               |  6 ++
 .../templates/update-motd.d/05-service.j2     |  3 +
 roles/unifi-controller/tasks/main.yml         |  6 ++
 .../templates/update-motd.d/05-service.j2     |  3 +
 roles/wireguard/tasks/main.yml                |  6 ++
 .../templates/update-motd.d/05-service.j2     |  3 +
 services_web.yml                              |  6 --
 16 files changed, 87 insertions(+), 91 deletions(-)
 create mode 100755 roles/framadate/templates/update-motd.d/05-service.j2
 create mode 100755 roles/grafana/templates/update-motd.d/05-service.j2
 delete mode 100644 roles/motd-role/tasks/main.yml
 delete mode 100755 roles/motd-role/templates/update-motd.d/05-service.j2
 create mode 100755 roles/prometheus/templates/update-motd.d/05-service.j2
 create mode 100755 roles/unifi-controller/templates/update-motd.d/05-service.j2
 create mode 100755 roles/wireguard/templates/update-motd.d/05-service.j2

diff --git a/README.md b/README.md
index 0deab845..051ca30a 100644
--- a/README.md
+++ b/README.md
@@ -1,26 +1,9 @@
-# Ansible
+# Recettes Ansible du Cr@ns
 
 Ensemble des recettes de déploiement Ansible pour les serveurs du Crans.
+Pour les utiliser, vérifiez que vous avez au moins Ansible 2.7.
 
-Ces politiques de déployement nécessite Ansible 2.7 ou plus récent.
-Le paquet dans Debian Buster est suffisamment à jour, sinon vous pouvez l'obtenir de la façon suivante :
-
-```bash
-pip3 install --user ansible
-```
-
-## Exécution d'un playbook
-
-Pour appliquer le playbook `base.yml` :
-```bash
-ansible-playbook --ask-vault-pass base.yml
-```
-
-Il est souhaitable de faire un test avant avec `--check` si on a des doutes !
-
-## FAQ
-
-### Ansible 101
+## Ansible 101
 
 Si vous n'avez jamais touché à Ansible avant, voilà une rapide introduction.
 
@@ -60,35 +43,6 @@ récupérer son résultat dans une varible, mettre une boucle dessus, mettre des
 N'oubliez pas d'aller lire l'excellent documentation de RedHat sur tous les modules
 d'Ansible !
 
-### Mettre sa clé SSH sur une machine
-
-```
-ssh-copy-id -i ~/.ssh/id_rsa_crans.pub zamok.crans.org
-```
-
-### Ignorer la fingerprint ECDSA du serveur (dangereux !)
-
-Il faut changer la variable d'environnement suivante :
-`ANSIBLE_HOST_KEY_CHECKING=0`.
-
-### Configurer la connexion au vlan adm
-
-Envoyer son agent SSH peut être dangereux ([source](https://heipei.io/2015/02/26/SSH-Agent-Forwarding-considered-harmful/)).
-
-On va utiliser plutôt `ProxyJump`.
-Dans la configuration SSH :
-
-```
-# Use a key to log on all Crans servers
-# and use a proxy server
-Host 10.231.136.* *.adm.crans.org
-    IdentityFile ~/.ssh/id_rsa_crans
-    ProxyJump vo.crans.org
-```
-
-Il faut savoir que depuis Ansible 2.5, des connexions persistantes sont créées
-vers les serveurs puis détruites à la fin de l'exécution.
-
 ### Gestion des groupes de machines
 
 Pour la majorité des groupes ont retrouve ce qu'il y avait dans BCFG2
@@ -125,3 +79,42 @@ on peut exécuter le module `setup` manuellement.
 ```
 ansible zamok.adm.crans.org -m setup --ask-vault-pass
 ```
+
+## Exécution d'Ansible
+
+### Configurer la connexion au vlan adm
+
+Envoyer son agent SSH peut être dangereux
+([source](https://heipei.io/2015/02/26/SSH-Agent-Forwarding-considered-harmful/)).
+
+On va utiliser plutôt `ProxyJump`.
+Dans la configuration SSH :
+
+```
+# Use a key to log on all Crans servers
+# and use a proxy server
+Host 10.231.136.* *.adm.crans.org
+    IdentityFile ~/.ssh/id_rsa_crans
+    ProxyJump vo.crans.org
+```
+
+Il faut savoir que depuis Ansible 2.5, des connexions persistantes sont créées
+vers les serveurs puis détruites à la fin de l'exécution.
+
+Il faut sa clé SSH configurée sur le serveur que l'on déploit.
+```bash
+ssh-copy-id zamok.crans.org
+```
+
+### Lancer Ansible
+
+Pour tester le playbook `base.yml` :
+```bash
+ansible-playbook --ask-vault-pass base.yml --check
+```
+
+Vous pouvez ensuite enlever `--check` si vous voulez appliquer les changements !
+
+Si vous avez des soucis de fingerprint ECDSA, vous pouvez ignorer une
+première fois (dangereux !) : `ANSIBLE_HOST_KEY_CHECKING=0 ansible-playbook...`.
+
diff --git a/monitoring.yml b/monitoring.yml
index 76481ade..7918cef2 100644
--- a/monitoring.yml
+++ b/monitoring.yml
@@ -13,16 +13,10 @@
 
     # Debian non-free mirror
     debian_mirror: http://mirror.adm.crans.org/debian
-
-    # Indicate service in motd
-    motd_role:
-      name: prometheus
-      path: /etc/prometheus/
   roles:
     - debian-non-free
     - prometheus
     - prometheus-alertmanager
-    - motd-role
 
 # Monitor all hosts
 - hosts: all
@@ -38,11 +32,5 @@
     ldap_user_tree: "cn=Utilisateurs,{{ ldap_base }}"
     ldap_grafana_bind_dn: "cn=grafana,ou=service-users,{{ ldap_base }}"
     ldap_grafana_passwd: "{{ vault_ldap_grafana_passwd }}"
-
-    # Indicate service in motd
-    motd_role:
-      name: grafana
-      path: /etc/grafana/
   roles:
     - grafana
-    - motd-role
diff --git a/network.yml b/network.yml
index 5c0cefc4..ce5b4b8f 100644
--- a/network.yml
+++ b/network.yml
@@ -4,14 +4,8 @@
   vars:
     # Debian mirror on adm
     debian_mirror: http://mirror.adm.crans.org/debian
-
-    # Indicate service in motd
-    motd_role:
-      name: wireguard
-      path: /etc/wireguard/
   roles:
     - wireguard
-    - motd-role
 
 # Deploy DHCP server
 - hosts: dhcp.adm.crans.org
@@ -37,11 +31,5 @@
 
 # Deploy Unifi Controller
 - hosts: unifi.adm.crans.org
-  vars:
-    # Indicate service in motd
-    motd_role:
-      name: unifi-controller
-      verbose_name: Le contrôleur Unifi
   roles:
     - unifi-controller
-    - motd-role
diff --git a/roles/framadate/tasks/main.yml b/roles/framadate/tasks/main.yml
index fa5840d0..a5a41214 100644
--- a/roles/framadate/tasks/main.yml
+++ b/roles/framadate/tasks/main.yml
@@ -34,3 +34,9 @@
 # cd framadate
 # sudo -u www-data touch admin/stdout.log
 # sudo chmod 600 admin/stdout.log
+
+- name: Indicate role in motd
+  template:
+    src: update-motd.d/05-service.j2
+    dest: /etc/update-motd.d/05-framadate
+    mode: 0755
diff --git a/roles/framadate/templates/update-motd.d/05-service.j2 b/roles/framadate/templates/update-motd.d/05-service.j2
new file mode 100755
index 00000000..a11ad719
--- /dev/null
+++ b/roles/framadate/templates/update-motd.d/05-service.j2
@@ -0,0 +1,3 @@
+#!/bin/sh
+# {{ ansible_managed }}
+echo "> framadate a été déployé sur cette machine.\n   Voir {{ framadate_path }}"
diff --git a/roles/grafana/tasks/main.yml b/roles/grafana/tasks/main.yml
index 2890217c..bec44338 100644
--- a/roles/grafana/tasks/main.yml
+++ b/roles/grafana/tasks/main.yml
@@ -78,3 +78,9 @@
     enabled: true
     state: started
     daemon_reload: true
+
+- name: Indicate role in motd
+  template:
+    src: update-motd.d/05-service.j2
+    dest: /etc/update-motd.d/05-grafana
+    mode: 0755
diff --git a/roles/grafana/templates/update-motd.d/05-service.j2 b/roles/grafana/templates/update-motd.d/05-service.j2
new file mode 100755
index 00000000..7fcb3e6c
--- /dev/null
+++ b/roles/grafana/templates/update-motd.d/05-service.j2
@@ -0,0 +1,3 @@
+#!/bin/sh
+# {{ ansible_managed }}
+echo "> grafana a été déployé sur cette machine.\n   Voir /etc/grafana/"
diff --git a/roles/motd-role/tasks/main.yml b/roles/motd-role/tasks/main.yml
deleted file mode 100644
index 8b2b9646..00000000
--- a/roles/motd-role/tasks/main.yml
+++ /dev/null
@@ -1,6 +0,0 @@
----
-- name: "Indicate {{ motd_role.name }} in motd"
-  template:
-    src: update-motd.d/05-service.j2
-    dest: "/etc/update-motd.d/05-{{ motd_role.name }}"
-    mode: 0755
diff --git a/roles/motd-role/templates/update-motd.d/05-service.j2 b/roles/motd-role/templates/update-motd.d/05-service.j2
deleted file mode 100755
index f78d7d29..00000000
--- a/roles/motd-role/templates/update-motd.d/05-service.j2
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-# {{ ansible_managed }}
-echo "✨ {% if motd_role.verbose_name is defined %}{{ motd_role.verbose_name }}{% else %}{{ motd_role.name|capitalize }}{% endif %} a été déployé sur cette machine."
-{% if motd_role.path is defined %}
-echo "   Voir {{ motd_role.path }}"
-{% endif %}
diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml
index c8c43c17..751f1279 100644
--- a/roles/prometheus/tasks/main.yml
+++ b/roles/prometheus/tasks/main.yml
@@ -52,3 +52,9 @@
     name: prometheus
     enabled: yes
     state: started
+
+- name: Indicate role in motd
+  template:
+    src: update-motd.d/05-service.j2
+    dest: /etc/update-motd.d/05-prometheus
+    mode: 0755
diff --git a/roles/prometheus/templates/update-motd.d/05-service.j2 b/roles/prometheus/templates/update-motd.d/05-service.j2
new file mode 100755
index 00000000..e1fcc2ee
--- /dev/null
+++ b/roles/prometheus/templates/update-motd.d/05-service.j2
@@ -0,0 +1,3 @@
+#!/bin/sh
+# {{ ansible_managed }}
+echo "> prometheus a été déployé sur cette machine.\n   Voir /etc/prometheus/"
diff --git a/roles/unifi-controller/tasks/main.yml b/roles/unifi-controller/tasks/main.yml
index 0ff14dda..7f886f25 100644
--- a/roles/unifi-controller/tasks/main.yml
+++ b/roles/unifi-controller/tasks/main.yml
@@ -39,3 +39,9 @@
   register: apt_result
   retries: 3
   until: apt_result is succeeded
+
+- name: Indicate role in motd
+  template:
+    src: update-motd.d/05-service.j2
+    dest: /etc/update-motd.d/05-unifi-controller
+    mode: 0755
diff --git a/roles/unifi-controller/templates/update-motd.d/05-service.j2 b/roles/unifi-controller/templates/update-motd.d/05-service.j2
new file mode 100755
index 00000000..b7687734
--- /dev/null
+++ b/roles/unifi-controller/templates/update-motd.d/05-service.j2
@@ -0,0 +1,3 @@
+#!/bin/sh
+# {{ ansible_managed }}
+echo "> Le contrôleur Unifi a été déployé sur cette machine."
diff --git a/roles/wireguard/tasks/main.yml b/roles/wireguard/tasks/main.yml
index 465ece18..8b73d2a1 100644
--- a/roles/wireguard/tasks/main.yml
+++ b/roles/wireguard/tasks/main.yml
@@ -18,3 +18,9 @@
   register: apt_result
   retries: 3
   until: apt_result is succeeded
+
+- name: Indicate role in motd
+  template:
+    src: update-motd.d/05-service.j2
+    dest: /etc/update-motd.d/05-wireguard
+    mode: 0755
diff --git a/roles/wireguard/templates/update-motd.d/05-service.j2 b/roles/wireguard/templates/update-motd.d/05-service.j2
new file mode 100755
index 00000000..f529c8bc
--- /dev/null
+++ b/roles/wireguard/templates/update-motd.d/05-service.j2
@@ -0,0 +1,3 @@
+#!/bin/sh
+# {{ ansible_managed }}
+echo "> wireguard a été déployé sur cette machine.\n   Voir /etc/wireguard/"
diff --git a/services_web.yml b/services_web.yml
index be69ece3..eaf6ac8f 100644
--- a/services_web.yml
+++ b/services_web.yml
@@ -14,11 +14,5 @@
     # you will have to `sudo -u THISUSER zsh` to debug
     framadate_user: www-data
     framadate_path: /var/www/framadate
-
-    # Indicate service in motd
-    motd_role:
-      name: framadate
-      path: "{{ framadate_path }}"
   roles:
     - framadate
-    - motd-role
-- 
GitLab