77 lines
3.1 KiB
YAML
77 lines
3.1 KiB
YAML
|
|
---
|
||
|
|
# Courriel du realm + « mot de passe oublie ». Voir defaults/main.yml.
|
||
|
|
#
|
||
|
|
# API d'administration et NON `kcadm.sh` : sur `smtpServer` (une map), kcadm
|
||
|
|
# accepte `-s smtpServer.host=…` COMME `-s 'smtpServer={"host":…}'`, sort en
|
||
|
|
# succes, n'ecrit rien — le champ restait `{ }` apres deux deploiements verts.
|
||
|
|
# Constate le 2026-08-08. Meme famille que le reste : une valeur declaree d'un
|
||
|
|
# cote, jamais verifiee de l'autre.
|
||
|
|
|
||
|
|
- name: Dériver l'hôte du relais SMTP depuis le plan
|
||
|
|
ansible.builtin.set_fact:
|
||
|
|
serveur_keycloak_smtp_hote: "{{ applications[serveur_keycloak_smtp_app].hote ~ '.' ~ domaine_interne }}"
|
||
|
|
when:
|
||
|
|
- serveur_keycloak_smtp_actif | bool
|
||
|
|
- ((applications | default({})).get(serveur_keycloak_smtp_app, {}).get('hote') | default('')) | length > 0
|
||
|
|
|
||
|
|
- name: Exiger un relais SMTP résolu
|
||
|
|
ansible.builtin.assert:
|
||
|
|
that:
|
||
|
|
- serveur_keycloak_smtp_hote | length > 0
|
||
|
|
fail_msg: >-
|
||
|
|
Aucun relais SMTP : l'application « {{ serveur_keycloak_smtp_app }} » n'est pas
|
||
|
|
déclarée au plan et `serveur_keycloak_smtp_hote` est vide. Activer
|
||
|
|
« mot de passe oublié » sans relais donnerait un écran qui promet un courriel
|
||
|
|
que personne n'enverrait.
|
||
|
|
when: serveur_keycloak_smtp_actif | bool
|
||
|
|
|
||
|
|
- name: Obtenir un jeton d'administration
|
||
|
|
ansible.builtin.uri:
|
||
|
|
url: "http://localhost:8080/realms/master/protocol/openid-connect/token"
|
||
|
|
method: POST
|
||
|
|
body_format: form-urlencoded
|
||
|
|
body:
|
||
|
|
grant_type: password
|
||
|
|
client_id: admin-cli
|
||
|
|
username: "{{ serveur_keycloak_admin_user }}"
|
||
|
|
password: "{{ serveur_keycloak_admin_password }}"
|
||
|
|
register: serveur_keycloak_smtp_jeton
|
||
|
|
no_log: true
|
||
|
|
|
||
|
|
- name: Lire la strophe courriel en place
|
||
|
|
ansible.builtin.uri:
|
||
|
|
url: "http://localhost:8080/admin/realms/{{ serveur_keycloak_realm }}"
|
||
|
|
headers:
|
||
|
|
Authorization: "Bearer {{ serveur_keycloak_smtp_jeton.json.access_token }}"
|
||
|
|
register: serveur_keycloak_realm_actuel
|
||
|
|
no_log: true
|
||
|
|
|
||
|
|
- name: Composer la strophe courriel attendue
|
||
|
|
ansible.builtin.set_fact:
|
||
|
|
serveur_keycloak_smtp_attendu:
|
||
|
|
host: "{{ serveur_keycloak_smtp_hote }}"
|
||
|
|
port: "{{ serveur_keycloak_smtp_port | string }}"
|
||
|
|
from: "{{ serveur_keycloak_smtp_expediteur }}"
|
||
|
|
fromDisplayName: "{{ serveur_keycloak_smtp_nom_expediteur }}"
|
||
|
|
starttls: "{{ serveur_keycloak_smtp_starttls | bool | string | lower }}"
|
||
|
|
auth: "false"
|
||
|
|
ssl: "false"
|
||
|
|
|
||
|
|
- name: Configurer le courriel du realm et le « mot de passe oublié »
|
||
|
|
ansible.builtin.uri:
|
||
|
|
url: "http://localhost:8080/admin/realms/{{ serveur_keycloak_realm }}"
|
||
|
|
method: PUT
|
||
|
|
status_code: [204]
|
||
|
|
headers:
|
||
|
|
Authorization: "Bearer {{ serveur_keycloak_smtp_jeton.json.access_token }}"
|
||
|
|
body_format: json
|
||
|
|
body:
|
||
|
|
smtpServer: "{{ serveur_keycloak_smtp_attendu }}"
|
||
|
|
resetPasswordAllowed: "{{ serveur_keycloak_reset_mot_de_passe | bool }}"
|
||
|
|
no_log: true
|
||
|
|
changed_when: true
|
||
|
|
when: >-
|
||
|
|
(serveur_keycloak_realm_actuel.json.smtpServer | default({})) != serveur_keycloak_smtp_attendu
|
||
|
|
or (serveur_keycloak_realm_actuel.json.resetPasswordAllowed | default(false) | bool)
|
||
|
|
!= (serveur_keycloak_reset_mot_de_passe | bool)
|