---

- name: upload ldap initial config
  template:
    src: config_ldapvi.j2
    dest: /root/evolinux_ldap_config.ldapvi
    mode: "0640"

- name: upload ldap initial entries
  template:
    src: first-entries.ldif.j2
    dest: /root/evolinux_ldap_first-entries.ldif
    mode: "0640"

- name: inject config
  command: ldapvi -Y EXTERNAL -h ldapi:// --ldapmodify /root/evolinux_ldap_config.ldapvi
  environment:
    TERM: xterm

- name: inject first entries
  command: slapadd -l /root/evolinux_ldap_first-entries.ldif

- name: upload custom schema
  copy:
    src: "{{ ldap_schema }}"
    dest: "/root/{{ ldap_schema }}"
    mode: "0640"
  when: ldap_schema is defined

- name: inject custom schema
  command: "ldapadd -Y EXTERNAL -H ldapi:/// -f /root/{{ ldap_schema }}"
  when: ldap_schema is defined