From: Frank Brehm Date: Tue, 17 Dec 2024 16:46:23 +0000 (+0100) Subject: Adding Ansible role roles/389ds-init-replication and using it in playbooks/enable... X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=8e3192ebe48c83e22655405670c512310b201669;p=pixelpark%2Fpp-admin-tools.git Adding Ansible role roles/389ds-init-replication and using it in playbooks/enable-ldap-server-replication.yaml --- diff --git a/playbooks/enable-ldap-server-replication.yaml b/playbooks/enable-ldap-server-replication.yaml index 09cd1c4..4c405e2 100644 --- a/playbooks/enable-ldap-server-replication.yaml +++ b/playbooks/enable-ldap-server-replication.yaml @@ -39,6 +39,24 @@ 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 @@ -69,6 +87,14 @@ 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 @@ -82,5 +108,17 @@ 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 index 0000000..fafca09 --- /dev/null +++ b/roles/389ds-init-replication/tasks/main.yaml @@ -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 index 0000000..baaa036 --- /dev/null +++ b/roles/389ds-init-replication/tasks/suffix.yaml @@ -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