]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding Ansible role roles/389ds-init-replication and using it in playbooks/enable...
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 17 Dec 2024 16:46:23 +0000 (17:46 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 17 Dec 2024 16:46:23 +0000 (17:46 +0100)
playbooks/enable-ldap-server-replication.yaml
roles/389ds-init-replication/tasks/main.yaml [new file with mode: 0644]
roles/389ds-init-replication/tasks/suffix.yaml [new file with mode: 0644]

index 09cd1c4708f934d6b63b6c5fca7cf41c5999ded3..4c405e2668f4160231a1c3386d30d0ba428429a8 100644 (file)
         msg: "The given host {{ ldapserver_to_enable | quote }} is not a valid LDAP server."
       when: found_ldapserver == false
 
+    - ansible.builtin.set_fact:
+        possible_source_hosts: []
+        source_host_for_init: ~
+
+    - name: 'Actions, if ldapserver_to_enable was set.'
+      when: ldapserver_to_enable is not empty
+      block:
+
+        - ansible.builtin.set_fact:
+            possible_source_hosts: "{{ possible_source_hosts + [item] }}"
+          when: "item != ldapserver_to_enable"
+          ignore_errors: true
+          with_inventory_hostnames:
+            - ldap_servers
+
+        - ansible.builtin.set_fact:
+            source_host_for_init: "{{ possible_source_hosts | ansible.builtin.random }}"
+
 - name: "Initial checks for the HAProxy."
   hosts: haproxy_servers
   gather_facts: false
       ansible.builtin.set_fact:
         ldapserver_to_enable: "{{ hostvars.localhost.ldapserver_to_enable }}"
 
+    - ansible.builtin.set_fact:
+        source_host_for_init: ~
+
+    - name: "Get the source LDAP server to init replication."
+      ansible.builtin.set_fact:
+        source_host_for_init: "{{ hostvars.localhost.source_host_for_init }}"
+      when: hostvars.localhost.source_host_for_init is not empty
+
     - name: "The LDAP server to enable replication:"
       debug:
         var: ldapserver_to_enable
       include_role:
         name: '389ds-ensure-repl-agmt'
 
+    - name: "Source host for init replication:"
+      debug:
+        var: source_host_for_init
+        verbosity: 2
+
+    - name: 'Init of the replica.'
+      include_role:
+        name: '389ds-init-replication'
+      when: ldapserver_to_enable is not empty and inventory_hostname == source_host_for_init
+      vars:
+        target_host: "{{ ldapserver_to_enable }}"
+
 
 # vim: filetype=yaml
diff --git a/roles/389ds-init-replication/tasks/main.yaml b/roles/389ds-init-replication/tasks/main.yaml
new file mode 100644 (file)
index 0000000..fafca09
--- /dev/null
@@ -0,0 +1,44 @@
+---
+
+# Performing an initial sending of replica from source host (inventory_host) to a target host on all suffixes.
+
+- debug:
+    msg: "Do an initial sending of replica from source host ({{ inventory_hostname }}) to the target host {{ target_host | quote }} on all suffixes."
+
+- name: "Retrieve all backends."
+  ansible.builtin.shell: "dsconf {{ slapd_instance | quote  }} backend suffix list"
+  register: get_backend_suffix_list
+  changed_when: false
+  check_mode: false
+
+- name: "Show current get_backend_suffix_list"
+  debug:
+    var: get_backend_suffix_list
+    verbosity: 2
+
+- name: "Set backend variable"
+  no_log: true
+  set_fact:
+    suffix_names: "{{ get_backend_suffix_list.stdout_lines | map('regex_replace', '\\s+\\(.+\\)\\s*$', '') | list }}"
+    backend_names: "{{ get_backend_suffix_list.stdout_lines | map('regex_replace', '^.*\\((.+)\\)\\s*$', '\\1') | list }}"
+
+- name: "Set suffixes dict"
+  no_log: true
+  set_fact:
+    suffixes: "{{ dict( suffix_names | zip(backend_names) ) }}"
+
+- name: "Show current suffixes"
+  debug:
+    var: suffixes
+    verbosity: 0
+
+- name: "Perform init of a replication agreement on all suffixes."
+  include_tasks: suffix.yaml
+  vars:
+    backend_name: "{{ backend.name }}"
+    suffix: "{{ backend.suffix }}"
+  loop: "{{ suffixes | dict2items(key_name='suffix', value_name='name') }}"
+  loop_control:
+    loop_var: backend
+
+# vim: filetype=yaml
diff --git a/roles/389ds-init-replication/tasks/suffix.yaml b/roles/389ds-init-replication/tasks/suffix.yaml
new file mode 100644 (file)
index 0000000..baaa036
--- /dev/null
@@ -0,0 +1,18 @@
+---
+
+- debug:
+    msg: "start init of replication agreement from {{ inventory_hostname | quote }} \
+          to {{ target_host | quote }} for suffix {{ suffix | quote }}."
+    verbosity: 0
+
+- name: "Set fact agreement_name."
+  set_fact:
+    agreement_name: "{{ slapd_instance }} to {{ target_host }} agreement"
+
+- name: "Show replication agreement name for suffix {{ suffix | quote }}."
+  debug:
+    var: agreement_name
+    verbosity: 0
+
+
+# vim: filetype=yaml