|
7 | 7 | group: "{{ fworch_group }}" |
8 | 8 | become: true |
9 | 9 |
|
| 10 | +- name: build ldap tls options |
| 11 | + set_fact: |
| 12 | + ldap_tls_opts: >- |
| 13 | + {% if openldap_server_enable_ssl | default(false) -%} |
| 14 | + -o TLS_REQCERT=never{% if openldap_server_cert is defined %} -o TLS_CACERT={{ openldap_server_cert }}{% endif %} |
| 15 | + {%- endif %} |
| 16 | + ldap_cmd_url: >- |
| 17 | + {% if openldap_server_enable_ssl | default(false) -%} |
| 18 | + ldaps://{{ openldap_server }}:{{ openldap_port | default(636) }} |
| 19 | + {%- else -%} |
| 20 | + ldap://{{ openldap_server }}:{{ (openldap_port | default(389) | int == 636) | ternary(389, openldap_port | default(389)) }} |
| 21 | + {%- endif %} |
| 22 | +
|
10 | 23 | - name: determine distinguished name and changetype |
11 | 24 | set_fact: |
12 | 25 | distinguished_name: "{{ item.splitlines()[0] }}" |
13 | 26 | changetype: "{{ item.split('changetype: ')[1].splitlines()[0] }}" |
14 | 27 |
|
15 | 28 | - name: test if distinguished name exists |
16 | 29 | # error code 32, when searchbase not existing |
17 | | - command: "ldapsearch -H {{ openldap_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -b {{ distinguished_name }}" |
| 30 | + command: "ldapsearch {{ ldap_tls_opts }} -H {{ ldap_cmd_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -b {{ distinguished_name }}" |
18 | 31 | #become: true |
19 | 32 | register: search_existence |
20 | 33 | failed_when: (search_existence.rc != 0) and (search_existence.rc != 32) |
21 | 34 |
|
22 | 35 | - name: add ldap entry if not existing |
23 | | - command: "ldapmodify -H {{ openldap_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -x -f {{ middleware_ldif_dir }}/{{ outer_item }}_{{ item.split(',')[0] }}.ldif" |
| 36 | + command: "ldapmodify {{ ldap_tls_opts }} -H {{ ldap_cmd_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -x -f {{ middleware_ldif_dir }}/{{ outer_item }}_{{ item.split(',')[0] }}.ldif" |
24 | 37 | when: (changetype == 'add') and (search_existence.stdout.split('result:')[1].splitlines()[0] is match('.*No such object')) |
25 | 38 | #become: true |
26 | 39 |
|
27 | 40 | - name: delete ldap entry if existing |
28 | 41 | # dont delete in case numEntries > 1, otherwise ldap nodes are disconected |
29 | | - command: "ldapmodify -H {{ openldap_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -x -f {{ middleware_ldif_dir }}/{{ outer_item }}_{{ item.split(',')[0] }}.ldif" |
| 42 | + command: "ldapmodify {{ ldap_tls_opts }} -H {{ ldap_cmd_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -x -f {{ middleware_ldif_dir }}/{{ outer_item }}_{{ item.split(',')[0] }}.ldif" |
30 | 43 | when: (changetype == 'delete') and (search_existence.stdout.split('# numEntries:')[1].splitlines()[0] is match('\s1')) |
31 | 44 | #become: true |
32 | 45 |
|
33 | 46 | - name: modify ldap entry if existing |
34 | 47 | # error code 20, when attribute already exists |
35 | | - command: "ldapmodify -H {{ openldap_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -x -f {{ middleware_ldif_dir }}/{{ outer_item }}_{{ item.split(',')[0] }}.ldif" |
| 48 | + command: "ldapmodify {{ ldap_tls_opts }} -H {{ ldap_cmd_url }} -D {{ openldap_superuser_dn }} -w {{ ldap_manager_pwd }} -x -f {{ middleware_ldif_dir }}/{{ outer_item }}_{{ item.split(',')[0] }}.ldif" |
36 | 49 | register: modify_out |
37 | 50 | when: (changetype == 'modify') and (search_existence.stdout.split('# numEntries:')[1].splitlines()[0] is match('\s1')) |
38 | 51 | #become: true |
|
0 commit comments