]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Finishing roles/389ds-config-plugins/tasks/attr-uniq-entry-modify.yaml
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 9 Dec 2024 13:53:36 +0000 (14:53 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 9 Dec 2024 13:53:36 +0000 (14:53 +0100)
roles/389ds-config-plugins/tasks/attr-uniq-entry-modify.yaml

index 9544efa5cf4d259aa2f6e1de668536b6fd5af4c1..b5793a1adf479eabf7c60da8ccfa1592e6e5c02c 100644 (file)
     var: attr_uniq_config
     verbosity: 0
 
-- name: 'Predefine variable exec_set to false'
+- name: 'Predefine variables exec_set, remove_attr_uniq_entry_before and exp_entry_enabled'
   set_fact:
     exec_set: false
-
-- name: 'Predefine variable remove_attr_uniq_entry_before'
-  set_fact:
     remove_attr_uniq_entry_before: false
-
-- name: "Set exp_entry_enabled to default true."
-  set_fact:
     exp_entry_enabled: true
 
 - name: "Set exp_entry_enabled by config."
@@ -53,7 +47,6 @@
 - name: "Set remove_attr_uniq_entry_before to true in case of no subtrees expected."
   set_fact:
     remove_attr_uniq_entry_before: true
-    exec_set: true
   when: "'subtrees' in attr_uniq_config and ('subtrees' not in entry_data or entry_data['subtrees'] | length == 0)"
 
 - name: "Set cur_subtrees to an empty list, if none were found"
@@ -79,7 +72,6 @@
 - name: "Check across-all-subtrees for should be vanished."
   set_fact:
     remove_attr_uniq_entry_before: true
-    exec_set: true
   when: "('across-all-subtrees' in attr_uniq_config) and ('across_all_subtrees' not in entry_data or entry_data['across_all_subtrees'] == None)"
 
 - name: "Check across-all-subtrees"
     exec_set: true
   when: "'across_all_subtrees' in entry_data and entry_data['across_all_subtrees'] != None and ('across-all-subtrees' not in attr_uniq_config or entry_data['across_all_subtrees'] != attr_uniq_config['across-all-subtrees'])"
 
+- name: "Check top-entry-oc for should be vanished."
+  set_fact:
+    remove_attr_uniq_entry_before: true
+  when: "('top-entry-oc' in attr_uniq_config) and ('top_entry_oc' not in entry_data or entry_data['top_entry_oc'] == None)"
+
+- name: 'Check top-entry-oc'
+  set_fact:
+    exec_set: true
+  when: "('top_entry_oc' in entry_data) and (entry_data['top_entry_oc'] != None) and (('top-entry-oc' not in attr_uniq_config) or ((attr_uniq_config['top-entry-oc'] | lower) != (entry_data['top_entry_oc'] | lower)) )"
+
+- name: "Check subtree-entries-oc for should be vanished."
+  set_fact:
+    remove_attr_uniq_entry_before: true
+  when: "('subtree-entries-oc' in attr_uniq_config) and ('subtree_entries_oc' not in entry_data or entry_data['subtree_entries_oc'] == None)"
+
+- name: 'Check subtree-entries-oc'
+  set_fact:
+    exec_set: true
+  when: "('subtree_entries_oc' in entry_data) and (entry_data['subtree_entries_oc'] != None) and (('subtree-entries-oc' not in attr_uniq_config) or ((attr_uniq_config['subtree-entries-oc'] | lower) != (entry_data['subtree_entries_oc'] | lower)) )"
+
+- name: 'Actions for removing attr-uniq entry.'
+  when: remove_attr_uniq_entry_before == true
+  block:
+
+    - name: 'The attr-uniq entry should be removed?'
+      debug:
+        msg: "Remove attr-uniq entry {{ entry_name | quote }} before: {{ remove_attr_uniq_entry_before }}."
+        verbosity: 0
+
+    - name: 'Ensure recreation of attr-uniq entry.'
+      set_fact:
+        exec_set: true
+
+    - name: 'Remove attr-uniq entry.'
+      ansible.builtin.shell: "dsconf {{ slapd_instance | quote }} plugin attr-uniq delete {{ entry_name | quote }}"
+
+- name: 'Actions for adding or modifying attr-uniq entry.'
+  when: exec_set == true
+  block:
+
+    - name: 'Start defining command for modifying attr-uniq entry.'
+      set_fact:
+        entry_set_cmd: "dsconf {{ slapd_instance | quote }} plugin attr-uniq set"
+      when: remove_attr_uniq_entry_before == false
+
+    - name: "Start defining command for adding an attr-uniq entry."
+      set_fact:
+        entry_set_cmd: "dsconf {{ slapd_instance | quote }} plugin attr-uniq add"
+      when: remove_attr_uniq_entry_before == true
+
+    - name: "Add enabled to entry_set_cmd."
+      set_fact:
+        entry_set_cmd: "{{ entry_set_cmd }} --enabled {{ entry_data['enabled'] | bool | default(true) | bool_to_on_off }}"
+
+    - name: "Adding attribute name to entry_set_cmd."
+      set_fact:
+        entry_set_cmd: "{{ entry_set_cmd }} --attr-name {{ attr_name | quote }}"
+
+    - name: "Adding subtrees to entry_set_cmd."
+      set_fact:
+        entry_set_cmd: "{{ entry_set_cmd }} --subtree {{ entry_data['subtrees'] | map('quote') | join(' ') }}"
+      when: "'subtrees' in entry_data and entry_data['subtrees'] | length > 0"
+
+    - name: "Adding across_all_subtrees to entry_set_cmd."
+      set_fact:
+        entry_set_cmd: "{{ entry_set_cmd }} --across-all-subtrees {{ entry_data['across_all_subtrees'] | default(true) | bool_to_on_off }}"
+
+    - name: "Adding top_entry_oc to entry_set_cmd."
+      set_fact:
+        entry_set_cmd: "{{ entry_set_cmd }} --top-entry-oc {{ entry_data['top_entry_oc'] | quote }}"
+      when: "'top_entry_oc' in entry_data and entry_data['top_entry_oc'] is defined and entry_data['top_entry_oc'] != None and entry_data['top_entry_oc'] | length > 0"
+
+    - name: "Adding subtree_entries_oc to entry_set_cmd."
+      set_fact:
+        entry_set_cmd: "{{ entry_set_cmd }} --subtree-entries-oc {{ entry_data['subtree_entries_oc'] | quote }}"
+      when: "'subtree_entries_oc' in entry_data and entry_data['subtree_entries_oc'] is defined and entry_data['subtree_entries_oc'] != None and entry_data['subtree_entries_oc'] | length > 0"
+
+    - name: "Adding entry name to entry_set_cmd."
+      set_fact:
+        entry_set_cmd: "{{ entry_set_cmd }} {{ entry_name | quote }}."
+
+    - name: "Show command for adding/modifying an attr-uniq entry."
+      debug:
+        var: entry_set_cmd
+        verbosity: 0
+
+- name: "Finally adding attr-uniq entry."
+  ansible.builtin.shell: "{{ entry_add_cmd }}"
+
+
 # vim: filetype=yaml