05_update.ymlΒΆ

---
- name: πŸ“Š Gather all users with their current objectClass list
  community.general.ldap_search:
    server_uri: "{{ OPENLDAP_SERVER_URI }}"
    bind_dn: "{{ OPENLDAP_BIND_DN }}"
    bind_pw: "{{ OPENLDAP_BIND_PW }}"
    dn: "{{ LDAP.DN.OU.USERS }}"
    scope: subordinate
    filter: "{{ LDAP.FILTERS.USERS.ALL }}"
    attrs:
      - dn
      - objectClass
      - "{{ LDAP.USER.ATTRIBUTES.ID }}"
  register: ldap_users_with_classes

- name: βž• Add only missing auxiliary classes
  ldap_entries:
    server_uri: "{{ OPENLDAP_SERVER_URI }}"
    bind_dn: "{{ OPENLDAP_BIND_DN }}"
    bind_pw: "{{ OPENLDAP_BIND_PW }}"
    state: present
    entries: >-
      {{ ldap_users_with_classes.results | map(attribute='dn')
         | ldap_dn_entries({'objectClass': LDAP.USER.OBJECTS.AUXILIARY.values() | list}) }}
  changed_when: false