]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
add a playbook that removes rbd-mirror from a node
authorRishabh Dave <ridave@redhat.com>
Tue, 25 Jun 2019 13:08:17 +0000 (18:38 +0530)
committerGuillaume Abrioux <gabrioux@redhat.com>
Mon, 15 Jul 2019 09:22:17 +0000 (11:22 +0200)
Add a playbook named "shrink-rbdmirror.yml" in infrastructure-playbooks/
that removes a RBD Mirror from a node in an already deployed Ceph
cluster.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1677431
Signed-off-by: Rishabh Dave <ridave@redhat.com>
infrastructure-playbooks/shrink-rbdmirror.yml [new file with mode: 0644]

diff --git a/infrastructure-playbooks/shrink-rbdmirror.yml b/infrastructure-playbooks/shrink-rbdmirror.yml
new file mode 100644 (file)
index 0000000..7d2fd19
--- /dev/null
@@ -0,0 +1,99 @@
+---
+# This playbook removes the Ceph RBD mirror from your cluster on the given
+# node.
+#
+# Use it like this:
+# ansible-playbook shrink-rbdmirror.yml -e rbdmirror_to_kill=ceph-rbdmirror01
+#     Prompts for confirmation to shrink, defaults to no and
+#     doesn't shrink the cluster. yes shrinks the cluster.
+#
+# ansible-playbook -e ireallymeanit=yes|no shrink-rbdmirror.yml
+#     Overrides the prompt using -e option. Can be used in
+#     automation scripts to avoid interactive prompt.
+
+- name: gather facts and check the init system
+  hosts:
+    - "{{ mon_group_name|default('mons') }}"
+    - "{{ mon_group_name|default('rbdmirrors') }}"
+  become: true
+  tasks:
+    - debug:
+        msg: gather facts on MONs and RBD mirrors
+
+- name: confirm whether user really meant to remove rbd mirror from the ceph
+        cluster
+  hosts: localhost
+  become: true
+  vars_prompt:
+    - name: ireallymeanit
+      prompt: Are you sure you want to shrink the cluster?
+      default: 'no'
+      private: no
+  pre_tasks:
+    - import_role:
+        name: ceph-defaults
+
+    - import_role:
+        name: ceph-facts
+
+    - name: exit playbook, if no rbdmirror was given
+      fail:
+        msg: "rbdmirror_to_kill must be declared
+          Exiting shrink-cluster playbook, no RBD mirror was removed.
+          On the command line when invoking the playbook, you can use
+          -e rbdmirror_to_kill=rbd-mirror01 argument. You can only remove a
+          single rbd mirror each time the playbook runs."
+      when: rbdmirror_to_kill is not defined
+
+    - name: exit playbook, if the rbdmirror is not part of the inventory
+      fail:
+        msg: >
+            It seems that the host given is not part of your inventory,
+            please make sure it is.
+      when: rbdmirror_to_kill not in groups[rbdmirror_group_name]
+
+    - name: exit playbook, if user did not mean to shrink cluster
+      fail:
+        msg: "Exiting shrink-rbdmirror playbook, no rbd-mirror was removed.
+           To shrink the cluster, either say 'yes' on the prompt or
+           or use `-e ireallymeanit=yes` on the command line when
+           invoking the playbook"
+      when: ireallymeanit != 'yes'
+
+    - name: set_fact container_exec_cmd for mon0
+      when: containerized_deployment | bool
+      set_fact:
+        container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }}"
+
+    - name: exit playbook, if can not connect to the cluster
+      command: "{{ container_exec_cmd | default('') }} timeout 5 ceph --cluster {{ cluster }} health"
+      register: ceph_health
+      until: ceph_health.rc
+      failed_when: ceph_health.rc != 0
+      delegate_to: "{{ groups[mon_group_name][0] }}"
+      retries: 5
+      delay: 2
+
+    - name: set_fact rbdmirror_to_kill_hostname
+      set_fact:
+        rbdmirror_to_kill_hostname: "{{ hostvars[rbdmirror_to_kill]['ansible_hostname'] }}"
+
+  tasks:
+    - name: stop rbdmirror service
+      service:
+        name: ceph-rbd-mirror@rbd-mirror.{{ rbdmirror_to_kill_hostname }}
+        state: stopped
+        enabled: no
+      delegate_to: "{{ rbdmirror_to_kill }}"
+      failed_when: false
+
+    - name: purge related directories
+      file:
+        path: /var/lib/ceph/bootstrap-rbd-mirror/{{ cluster }}-{{ rbdmirror_to_kill_hostname }}
+        state: absent
+      delegate_to: "{{ rbdmirror_to_kill }}"
+
+  post_tasks:
+    - name: show ceph health
+      command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} -s"
+      delegate_to: "{{ groups[mon_group_name][0] }}"