From a6b371b6468bef557e77fbd99fb19712ec3a1a32 Mon Sep 17 00:00:00 2001 From: Teoman ONAY Date: Fri, 24 Nov 2023 18:28:11 +0100 Subject: [PATCH] purge: do not purge infra pkgs by default By default infra pkgs will remain installed after the cluster purge as they might already be there at Ceph installation and could be used by other processes on the nodes. Fixes: https://github.com/ceph/cephadm-ansible/issues/239 Signed-off-by: Teoman ONAY --- ceph_defaults/defaults/main.yml | 5 +-- cephadm-clients.yml | 64 +++++++++++++++++---------------- cephadm-preflight.yml | 2 +- cephadm-purge-cluster.yml | 57 ++++++++++++++++------------- 4 files changed, 69 insertions(+), 59 deletions(-) diff --git a/ceph_defaults/defaults/main.yml b/ceph_defaults/defaults/main.yml index 29b62dd..ba8009b 100644 --- a/ceph_defaults/defaults/main.yml +++ b/ceph_defaults/defaults/main.yml @@ -12,11 +12,12 @@ ceph_ibm_key: https://public.dhe.ibm.com/ibmdl/export/pub/storage/ceph/RPM-GPG-K ceph_release: quincy upgrade_ceph_packages: false ceph_pkgs: - - chrony - cephadm - - podman - ceph-common ceph_client_pkgs: - chrony - ceph-common +infra_pkgs: + - chrony + - podman client_group: clients diff --git a/cephadm-clients.yml b/cephadm-clients.yml index 272903f..5c65720 100644 --- a/cephadm-clients.yml +++ b/cephadm-clients.yml @@ -26,39 +26,41 @@ - name: Confirm local readiness - hosts: localhost + hosts: all gather_facts: false tasks: - - - name: import_role ceph_defaults - import_role: - name: ceph_defaults - - - name: fail if the fsid parameter is missing - fail: - msg: > - You must supply an 'fsid' parameter for the corresponding ceph cluster - when: fsid is undefined - - - name: fail if admin group doesn't exist or is empty - fail: - msg: | - You must define a group [admin] in your inventory which provides the - keyring that you want to distribute - when: "'admin' not in groups or groups['admin'] | length < 1" - - - name: fail if client_group is NOT in the inventory - fail: - msg: > - Variable client_group '{{ client_group }}' is not defined in the inventory - when: client_group not in groups - - - name: fail if keyring variable is missing - fail: - msg: | - You must supply a 'keyring' variable that defines the path to the key - that you want to distribute to your client machines - when: keyring is not defined + - run_once: true + delegate_to: localhost + block: + - name: import_role ceph_defaults + import_role: + name: ceph_defaults + + - name: fail if the fsid parameter is missing + fail: + msg: > + You must supply an 'fsid' parameter for the corresponding ceph cluster + when: fsid is undefined + + - name: fail if admin group doesn't exist or is empty + fail: + msg: | + You must define a group [admin] in your inventory which provides the + keyring that you want to distribute + when: "'admin' not in groups or groups['admin'] | length < 1" + + - name: fail if client_group is NOT in the inventory + fail: + msg: > + Variable client_group '{{ client_group }}' is not defined in the inventory + when: client_group not in groups + + - name: fail if keyring variable is missing + fail: + msg: | + You must supply a 'keyring' variable that defines the path to the key + that you want to distribute to your client machines + when: keyring is not defined - name: Confirm admin host is ready diff --git a/cephadm-preflight.yml b/cephadm-preflight.yml index aa3f57f..ba15fb4 100644 --- a/cephadm-preflight.yml +++ b/cephadm-preflight.yml @@ -191,7 +191,7 @@ - name: install prerequisites packages package: - name: "{{ ceph_pkgs }}" + name: "{{ ceph_pkgs + infra_pkgs }}" state: "{{ (upgrade_ceph_packages | bool) | ternary('latest', 'present') }}" register: result until: result is succeeded diff --git a/cephadm-purge-cluster.yml b/cephadm-purge-cluster.yml index 725883d..3d556c8 100644 --- a/cephadm-purge-cluster.yml +++ b/cephadm-purge-cluster.yml @@ -13,26 +13,28 @@ - name: check local prerequisites are in place - hosts: localhost + hosts: all gather_facts: false become: true any_errors_fatal: true - tasks: - - name: fail if fsid was not provided - fail: - msg: | - You must provide the cluster fsid to be purged. - e.g. ansible-playbook -i cephadm-purge-cluster.yml -e fsid= - when: fsid is undefined - - - name: fail if admin group doesn't exist or is empty - fail: - msg: | - You must define a group [admin] in your inventory and add a node where - admin keyring is present at /etc/ceph/ceph.client.admin.keyring - when: "'admin' not in groups or groups['admin'] | length < 1" + - run_once: true + delegate_to: localhost + block: + - name: fail if fsid was not provided + fail: + msg: | + You must provide the cluster fsid to be purged. + e.g. ansible-playbook -i cephadm-purge-cluster.yml -e fsid= + when: fsid is undefined + + - name: fail if admin group doesn't exist or is empty + fail: + msg: | + You must define a group [admin] in your inventory and add a node where + admin keyring is present at /etc/ceph/ceph.client.admin.keyring + when: "'admin' not in groups or groups['admin'] | length < 1" - name: check keyring is present on the admin host hosts: admin[0] @@ -53,7 +55,7 @@ - name: check cluster hosts have cephadm and the required fsid {{ fsid }} - hosts: all + hosts: all,!{{ client_group }} gather_facts: false become: true any_errors_fatal: true @@ -68,7 +70,6 @@ register: cephadm_exists changed_when: false failed_when: false - when: group_names != [client_group] - name: fail if cephadm is not available fail: @@ -76,14 +77,12 @@ The cephadm binary is missing on {{ inventory_hostname }}. To purge the cluster you must have cephadm installed on ALL ceph hosts. Install manually or use the preflight playbook. when: - - group_names != [client_group] - cephadm_exists.rc - name: check fsid directory given is valid across the cluster stat: path: /var/lib/ceph/{{ fsid }} register: fsid_exists - when: group_names != [client_group] - name: fail if the fsid directory is missing fail: @@ -91,12 +90,11 @@ The fsid directory '/var/lib/ceph/{{ fsid }}' can not be found on {{ inventory_hostname }} Is the fsid correct? when: - - group_names != [client_group] - not fsid_exists.stat.exists | bool - name: confirm whether user really wants to purge the cluster - hosts: localhost + hosts: all gather_facts: false become: false @@ -110,6 +108,8 @@ tasks: - name: exit playbook, if user did not mean to purge cluster + run_once: true + delegate_to: localhost fail: msg: | Exiting cephadm-purge-cluster playbook, cluster was NOT purged. @@ -129,7 +129,7 @@ - name: Purge ceph daemons from all hosts in the cluster - hosts: all + hosts: all,!{{ client_group }} become: true gather_facts: false any_errors_fatal: true @@ -140,7 +140,6 @@ - name: purge ceph daemons command: "cephadm rm-cluster --force --zap-osds --fsid {{ fsid }}" - when: group_names != [client_group] - name: remove ceph packages @@ -153,9 +152,17 @@ import_role: name: ceph_defaults - - name: remove ceph packages + - name: remove ceph packages on servers + package: + name: {{ ceph_pkgs | unique }} + state: absent + register: result + until: result is succeeded + + - name: remove ceph packages on clients package: - name: "{{ 'ceph-common' if group_names == [client_group] else ceph_pkgs | unique }}" + name: ceph-common state: absent register: result until: result is succeeded +