remoteauth.yml 66 lignes · 3121 octets
---
# Mots de passe en transition (OI-104, D-061 amendée) : overlay remoteauth sur la base principale,
# placé sous ppolicy (index 0, au plus près de la base) : ppolicy refuse toujours un compte
# verrouillé et compte les échecs, que le mot de passe soit vérifié par l'AD ou localement. Une
# entrée qui porte un userPassword (compte local, ou compte importé après son premier changement)
# s'authentifie localement. Appliqué en ligne : vaut pour un annuaire neuf comme existant.
- name: Écrire les autorités des sources Active Directory (lues par slapd)
  ansible.builtin.copy:
    dest: "{{ oiam_ldap_remoteauth_autorites }}"
    content: "{{ oiam_ldap_remoteauth_sources | map(attribute='certificat') | map('trim') | join('\n') }}\n"
    owner: root
    group: ldap
    mode: "0640"
  # remoteauth garde son contexte TLS : de nouvelles autorités ne valent qu'après redémarrage.
  notify: Redémarrer l'annuaire

- name: Lire les modules chargés par slapd
  ansible.builtin.command:
    argv: ["{{ oiam_ldap_prefixe }}/bin/ldapsearch", -LLL, -Q, -Y, EXTERNAL, -H, "{{ oiam_ldap_ldapi }}",
           -b, "cn=module{0},cn=config", -s, base, olcModuleLoad]
  register: oiam_ldap_modules_charges
  changed_when: false

- name: Charger le module remoteauth
  ansible.builtin.command:
    argv: ["{{ oiam_ldap_prefixe }}/bin/ldapmodify", -Q, -Y, EXTERNAL, -H, "{{ oiam_ldap_ldapi }}"]
    stdin: |
      dn: cn=module{0},cn=config
      changetype: modify
      add: olcModuleLoad
      olcModuleLoad: remoteauth.la
  when: >-
    oiam_ldap_modules_charges.stdout is not search('(?m)^olcModuleLoad: (\{[0-9]+\})?remoteauth\.la$')
  changed_when: true

- name: Chercher l'overlay remoteauth
  ansible.builtin.command:
    argv: ["{{ oiam_ldap_prefixe }}/bin/ldapsearch", -LLL, -Q, -Y, EXTERNAL, -H, "{{ oiam_ldap_ldapi }}",
           -b, "olcDatabase={2}mdb,cn=config", -s, one, "(objectClass=olcRemoteAuthCfg)", dn]
  register: oiam_ldap_remoteauth_present
  changed_when: false

- name: Retenir la configuration voulue de remoteauth
  ansible.builtin.template:
    src: remoteauth.ldif.j2
    dest: "{{ oiam_ldap_remoteauth_reference }}"
    owner: root
    group: root
    mode: "0600"
  register: oiam_ldap_remoteauth_reference_ecrite

- name: Ajouter l'overlay remoteauth sous ppolicy
  ansible.builtin.command:
    argv: ["{{ oiam_ldap_prefixe }}/bin/ldapadd", -Q, -Y, EXTERNAL, -H, "{{ oiam_ldap_ldapi }}"]
    stdin: "{{ lookup('ansible.builtin.template', 'remoteauth.ldif.j2') }}"
  when: oiam_ldap_remoteauth_present.stdout | length == 0
  changed_when: true

- name: Mettre à jour la configuration de remoteauth (sources changées)
  ansible.builtin.command:
    argv: ["{{ oiam_ldap_prefixe }}/bin/ldapmodify", -Q, -Y, EXTERNAL, -H, "{{ oiam_ldap_ldapi }}"]
    stdin: "{{ lookup('ansible.builtin.template', 'remoteauth.ldif.j2') }}"
  vars:
    oiam_ldap_remoteauth_dn: "{{ oiam_ldap_remoteauth_present.stdout | regex_search('(?m)^dn: (.*)$', '\\1') | first }}"
  when: oiam_ldap_remoteauth_present.stdout | length > 0 and oiam_ldap_remoteauth_reference_ecrite is changed
  changed_when: true