- name: Get 389-ds-base version
  dnf:
    list: 389-ds-base
  register: pkg

- name: Setup DS Service
  shell: dscreate fromfile /tmp/test_dir/ldap.cfg
  when: (topology  == "topology-01" or topology == "topology-02" or topology == "topology-03" or topology == "topology-04" or topology  == "topology-05" or topology == "topology-ecc" or topology == "topology-SubCA") and pkg.results[0].version <= "1.4.0.16"

- name: Setup DS Service
  shell: dscreate from-file /tmp/test_dir/ldap.cfg
  when: (topology == "acme" or topology  == "topology-01" or topology == "topology-02" or topology == "topology-03" or topology == "topology-04" or topology  == "topology-05" or topology == "topology-ecc" or topology == "topology-SubCA") and pkg.results[0].version >= "1.4.0.20"

- name: INC_CONSTANTS
  include_vars:
    file: /tmp/test_dir/constants.yml
    name: variable

- name: Enable TLS enabled LDAP server
  block:
    - name: Enable TLS enabled LDAP server
      shell: sh /tmp/test_dir/setupssl2.sh -d /etc/dirsrv/slapd-{{topology}}-testingmaster -p {{ variable.LDAP_PORT }} -t {{ variable.LDAPS_PORT }} -pass {{ variable.LDAP_PASSWD }}

    - name: Restart directory server
      shell: systemctl restart dirsrv@{{topology}}-testingmaster

    - name: Export CA certificate to the pem file.
      shell: certutil -L -d /etc/dirsrv/slapd-{{topology}}-testingmaster -n "CA certificate" -a -o /root/ca-cert.pem
  when: tls_ldap == "true"

- name: Setup DS Service
  shell: dscreate fromfile /tmp/test_dir/ldap_kra.cfg
  when: topology  == "topology-05"

- name: Setup DS Service
  shell: dscreate fromfile /tmp/test_dir/ldap_ocsp.cfg
  when: topology  == "topology-05"

- name: Setup DS Service
  shell: dscreate fromfile /tmp/test_dir/ldap_tks.cfg
  when: topology  == "topology-05"

- name: Setup DS Service
  shell: dscreate fromfile /tmp/test_dir/ldap_tps.cfg
  when: topology  == "topology-05"

- name: sleep
  shell: sleep 5s

- name: ldap aci anonymous access file
  copy:
    dest: /tmp/ldapaci.ldif
    content: |
      dn: {{ variable.LDAP_BASE_DN }}
      changetype: modify
      add: aci
      aci: (targetattr!="userPassword || aci")(version 3.0; acl "Enable anonymous access"; allow (read, search, compare) userdn="ldap:///anyone";)

- name: Enable anonymous access on ldap
  shell: ldapmodify -x -h {{ inventory_hostname }} -p {{ variable.LDAP_PORT }} -D "cn=Directory Manager" -w {{ variable.LDAP_PASSWD }} -f /tmp/ldapaci.ldif
  when: topology  == "topology-01" or topology == "topology-02" or topology == "topology-03" or topology == "topology-04" or topology  == "topology-05" or topology == "topology-ecc" or topology == "topology-SubCA"
