From 539d549ff5cc7e3b1f06b068dc35b9fb061291d6 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 2 Dec 2024 11:55:52 +0100 Subject: [PATCH] Adding and using role 389ds-del-repl-agmt --- .../del-389ds-backend-repl-agmts-src.yaml | 7 ------ .../del-389ds-backend-repl-agmts-target.yaml | 24 ------------------- playbooks/disable-ldap-server.yaml | 13 +++++----- .../tasks/del-repl-agmt.yaml | 0 roles/389ds-del-repl-agmt/tasks/main.yaml | 17 +++++++++++++ 5 files changed, 24 insertions(+), 37 deletions(-) delete mode 100644 includes/del-389ds-backend-repl-agmts-src.yaml delete mode 100644 includes/del-389ds-backend-repl-agmts-target.yaml rename includes/del-389ds-backend-repl-agmt.yaml => roles/389ds-del-repl-agmt/tasks/del-repl-agmt.yaml (100%) create mode 100644 roles/389ds-del-repl-agmt/tasks/main.yaml diff --git a/includes/del-389ds-backend-repl-agmts-src.yaml b/includes/del-389ds-backend-repl-agmts-src.yaml deleted file mode 100644 index b964d0d..0000000 --- a/includes/del-389ds-backend-repl-agmts-src.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- - -- name: "Removing replication agreement to '{{ target }}' on suffix '{{ suffix }}'." - include_tasks: '../includes/del-389ds-backend-repl-agmt.yaml' - when: target == ldapserver_to_disable - -# vim: filetype=yaml diff --git a/includes/del-389ds-backend-repl-agmts-target.yaml b/includes/del-389ds-backend-repl-agmts-target.yaml deleted file mode 100644 index 711ca2b..0000000 --- a/includes/del-389ds-backend-repl-agmts-target.yaml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -# name: "Removing replication agreements to '{{ target }}' on suffix '{{ suffix }}'." -# when: target != ansible_fqdn -# block: - -# - name: "Set fact agreement_name." -# set_fact: -# agreement_name: "{{ slapd_instance }} to {{ target }} agreement" - -# - name: "Show replication agreement name for suffix '{{ suffix }}'." -# debug: -# var: agreement_name -# verbosity: 0 - -# - name: "Removing replication agreement '{{ agreement_name }}' for suffix '{{ suffix }}'." -# ansible.builtin.shell: "dsconf '{{ slapd_instance }}' repl-agmt delete --suffix '{{ suffix }}' '{{ agreement_name }}'" -# ignore_errors: true - -- name: "Removing replication agreements to '{{ target }}' on suffix '{{ suffix }}'." - when: target != ansible_fqdn - include_tasks: '../includes/del-389ds-backend-repl-agmt.yaml' - -# vim: filetype=yaml diff --git a/playbooks/disable-ldap-server.yaml b/playbooks/disable-ldap-server.yaml index 5733306..ea95f35 100644 --- a/playbooks/disable-ldap-server.yaml +++ b/playbooks/disable-ldap-server.yaml @@ -58,12 +58,9 @@ backend: "{{ haproxy_backend_name }}" backend_server: "{{ ldapserver_to_disable }}" - # - name: "Fail for stop." - # ansible.builtin.fail: - # msg: "Hard stopping here ..." - - name: "Disabling Replication on the given host." hosts: ldap_servers + gather_facts: false tasks: @@ -174,17 +171,21 @@ loop_var: backend - name: "Removing replication agreements on host to disable." - include_tasks: '../includes/del-389ds-backend-repl-agmts-target.yaml' + include_role: + name: 389ds-del-repl-agmt when: ldapserver_to_disable == inventory_hostname vars: + direction: 'from-disabled' suffix: "{{ item[0].key }}" target: "{{ item[1] }}" loop: "{{ suffixes | dict2items | product( ansible_play_batch ) | list }}" - name: "Removing replication agreements on hosts to keep." - include_tasks: '../includes/del-389ds-backend-repl-agmts-src.yaml' + include_role: + name: 389ds-del-repl-agmt when: ldapserver_to_disable != inventory_hostname vars: + direction: 'to-disabled' suffix: "{{ item[0].key }}" target: "{{ item[1] }}" loop: "{{ suffixes | dict2items | product( ansible_play_batch ) | list }}" diff --git a/includes/del-389ds-backend-repl-agmt.yaml b/roles/389ds-del-repl-agmt/tasks/del-repl-agmt.yaml similarity index 100% rename from includes/del-389ds-backend-repl-agmt.yaml rename to roles/389ds-del-repl-agmt/tasks/del-repl-agmt.yaml diff --git a/roles/389ds-del-repl-agmt/tasks/main.yaml b/roles/389ds-del-repl-agmt/tasks/main.yaml new file mode 100644 index 0000000..942b531 --- /dev/null +++ b/roles/389ds-del-repl-agmt/tasks/main.yaml @@ -0,0 +1,17 @@ +--- + +- name: "Removing replication agreements." + debug: + var: direction + verbosity: 0 + +- name: "Removing replication agreements to '{{ target }}' on suffix '{{ suffix }}'." + when: direction == 'from-disabled' and target != inventory_hostname + include_tasks: 'del-repl-agmt.yaml' + +- name: "Removing replication agreement to '{{ target }}' on suffix '{{ suffix }}'." + when: direction == 'to-disabled' and target == ldapserver_to_disable + include_tasks: 'del-repl-agmt.yaml' + + +# vim: filetype=yaml -- 2.39.5