slapd: can take a list of ldif file to be injected as a list variable

This commit is contained in:
2019-09-10 22:49:40 +02:00
parent 66d46b90f2
commit baf98d3a96
4 changed files with 37 additions and 22 deletions

View File

@@ -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

View File

@@ -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"

9
tasks/inject_ldif.yml Normal file
View File

@@ -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

View File

@@ -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