- name: "pkgmgr install"
  include_role:
    name: pkgmgr-install
  vars:
    package_name: ldapsm

- name: Ensure custom LDAP schema snippet via ldapsm
  vars:
    schema_name: "nextcloud"
    attribute_defs:
      - "( 1.3.6.1.4.1.99999.1 NAME '{{ ldap.user.attributes.nextcloud_quota }}' DESC 'Quota for Nextcloud' EQUALITY integerMatch ORDERING integerOrderingMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )"
    objectclass_defs:
      - "( 1.3.6.1.4.1.99999.2 NAME 'nextcloudUser' DESC 'Auxiliary class for Nextcloud attributes' AUXILIARY MAY ( {{ ldap.user.attributes.nextcloud_quota }} ) )"
  command: >
    ldapsm
      -s {{ openldap_server_uri }}
      -D '{{ openldap_bind_dn }}'
      -W '{{ openldap_bind_pw }}'
      -n {{ schema_name }}
      {% for at in attribute_defs %}
      -a "{{ at }}"
      {% endfor %}
      {% for oc in objectclass_defs %}
      -c "{{ oc }}"
      {% endfor %}
  register: ldapsm_result
  changed_when: "'Created schema entry' in ldapsm_result.stdout"
  check_mode: no

- name: Show ldapsm output
  debug:
    var: ldapsm_result.stdout_lines