diff --git a/README.md b/README.md index 4201591..379b68b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ defined in vars/main.yml and vars/CentOS.yml * ldap_ssl_cert_path - {{ ldap_ssl_dir }}/{{ ansible_fqdn }}_fullchain.pem * ldap_ssl_cacert_path - {{ ldap_ssl_dir }}/{{ ansible_fqdn }}_fullchain.pem * ldap_ssl_key_path - {{ ldap_ssl_dir }}/{{ ansible_fqdn }}_privkey.pem + * ldap_ldif_files - optional list of ldif files to send to server and inject. + Will be templated. need absolute path Dependencies diff --git a/tasks/import_ldap_schema.yml b/tasks/import_ldap_schema.yml index 8797813..8e77aae 100644 --- a/tasks/import_ldap_schema.yml +++ b/tasks/import_ldap_schema.yml @@ -1,10 +1,7 @@ -- name: debug - debug: - msg: "schema {{ schema }}" - - name: check if schema is loaded command: "ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config dn" register: ldap_schema_list + changed_when - name: import additional schemas command: "ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/{{ schema }}.ldif" diff --git a/tasks/inject_ldif.yml b/tasks/inject_ldif.yml new file mode 100644 index 0000000..9d82309 --- /dev/null +++ b/tasks/inject_ldif.yml @@ -0,0 +1,9 @@ +- name: copy ldif files + copy: + src: "{{ ldap_ldif_dir }}/{{ ldif }}" + dest: "/root/Ldif/{{ ldif }}" + +- name: import additional schemas + command: "ldapadd -s /root/.ldap.secret -D {{ ldap_admin_dn }} -x /root/Ldif/{{ ldif }} -c" + ignore_error: true + diff --git a/tasks/main.yml b/tasks/main.yml index 3e4b8f5..50a7f00 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -62,24 +62,26 @@ state: directory mode: 0700 - - name: send ldif files - template: - src: "{{ item }}" - dest: /root/Ldif/ - mode: 0600 - with_fileglob: "templates/[0-9]*.ldif" + block: + - name: send ldif files + template: + src: "{{ item }}" + dest: /root/Ldif/ + mode: 0600 + loop: "{{ ldap_ldif_files }}" - - name: get list of ldif files - find: - paths: /root/Ldif - patterns: "*.ldif" - file_type: file - register: ldif_list + - name: get list of ldif files + find: + paths: /root/Ldif + patterns: "*.ldif" + file_type: file + register: ldif_list - - name: import ldif files - command: "ldapadd -y /root/.ldap.secrets -xD {{ ldap_admin_dn }} -f {{ item .path}}" - with_items: "{{ ldif_list.files }}" - when: import_data == true + - name: import ldif files + command: "ldapadd -y -c /root/.ldap.secrets -xD {{ ldap_admin_dn }} -f {{ item .path}}" + with_items: "{{ ldif_list.files }}" + ignore_errors: true + when: ldap_ldif_files is defined - name: configure replication provider include_tasks: replication_provider.yml @@ -118,9 +120,14 @@ - name: send ldif file template: src: ssl.ldif - dest: /root/Ldif/ + dest: /root/ - name: import ldif - command: ldapmodify -c -Y EXTERNAL -H ldapi:/// -f /root/Ldif/ssl.ldif + command: ldapmodify -c -Y EXTERNAL -H ldapi:/// -f /root/ssl.ldif + + - name: remove ldif + file: + path: /root/ssl.ldif + state: absent when: ldap_have_ssl