From 32b84e7e8e27e2ec824238cc0a92616f4d3801c2 Mon Sep 17 00:00:00 2001
From: Guillaume Abrioux <gabrioux@redhat.com>
Date: Mon, 1 Aug 2022 20:18:50 +0200
Subject: [PATCH] rbd-mirror: follow up on recent rbd-mirror refactor

- ensure /var/lib/ceph/bootstrap-rbd-mirror exists
- always install ceph-base on rbdmirror nodes (otherwise, ceph-crash
  isn't present)

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit 041435e1e371f00b7112efed3306beec91d5a434)
(cherry picked from commit b634fb1cb3cef6d895678501dfcd817a4fdea99c)
---
 ...om-non-containerized-to-containerized-ceph-daemons.yml | 8 +++++++-
 roles/ceph-common/vars/main.yml                           | 3 +++
 roles/ceph-rbd-mirror/tasks/configure_mirroring.yml       | 7 +++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml b/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml
index d07e271d0b..6b248a08e2 100644
--- a/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml
+++ b/infrastructure-playbooks/switch-from-non-containerized-to-containerized-ceph-daemons.yml
@@ -565,11 +565,17 @@
   serial: 1
   become: true
   pre_tasks:
+    - name: check for ceph rbd mirror services
+      command: systemctl show --no-pager --property=Id --state=enabled ceph-rbd-mirror@*  # noqa 303
+      changed_when: false
+      register: rbdmirror_services
+
     - name: stop non-containerized ceph rbd mirror(s)
       service:
-        name: "ceph-rbd-mirror@rbd-mirror.{{ ansible_facts['hostname'] }}"
+        name: "{{ item.split('=')[1] }}"
         state: stopped
         enabled: no
+      loop: "{{ rbdmirror_services.stdout_lines }}"
 
     - name: remove old systemd unit files
       file:
diff --git a/roles/ceph-common/vars/main.yml b/roles/ceph-common/vars/main.yml
index d4aead75aa..9409734573 100644
--- a/roles/ceph-common/vars/main.yml
+++ b/roles/ceph-common/vars/main.yml
@@ -9,6 +9,7 @@ debian_ceph_pkgs:
   - "{{ (ceph_test | bool) | ternary('ceph-test', 'ceph-common') }}"
   - "{{ (rgw_group_name in group_names) | ternary('radosgw', 'ceph-common') }}"
   - "{{ ((ceph_repository == 'rhcs') and (client_group_name in group_names)) | ternary('ceph-fuse', 'ceph-common') }}"
+  - "{{ (rbdmirror_group_name in group_names) | ternary('ceph-base', 'ceph-common') }}"
 
 redhat_ceph_pkgs:
   - "{{ (ceph_test | bool) | ternary('ceph-test', 'ceph-common') }}"
@@ -18,6 +19,7 @@ redhat_ceph_pkgs:
   - "{{ (client_group_name in group_names) | ternary('ceph-fuse', 'ceph-common') }}"
   - "{{ (client_group_name in group_names) | ternary('ceph-base', 'ceph-common') }}"
   - "{{ (rgw_group_name in group_names) | ternary('ceph-radosgw', 'ceph-common') }}"
+  - "{{ (rbdmirror_group_name in group_names) | ternary('ceph-base', 'ceph-common') }}"
 
 suse_ceph_pkgs:
   - "{{ (ceph_test | bool) | ternary('ceph-test', 'ceph-common') }}"
@@ -27,3 +29,4 @@ suse_ceph_pkgs:
   - "{{ (client_group_name in group_names) | ternary('ceph-fuse', 'ceph-common') }}"
   - "{{ (client_group_name in group_names) | ternary('ceph-base', 'ceph-common') }}"
   - "{{ (rgw_group_name in group_names) | ternary('ceph-radosgw', 'ceph-common') }}"
+  - "{{ (rbdmirror_group_name in group_names) | ternary('ceph-base', 'ceph-common') }}"
diff --git a/roles/ceph-rbd-mirror/tasks/configure_mirroring.yml b/roles/ceph-rbd-mirror/tasks/configure_mirroring.yml
index 4c323df8d3..de547a7866 100644
--- a/roles/ceph-rbd-mirror/tasks/configure_mirroring.yml
+++ b/roles/ceph-rbd-mirror/tasks/configure_mirroring.yml
@@ -17,6 +17,13 @@
       run_once: true
       no_log: "{{ no_log_on_ceph_key_tasks }}"
 
+    - name: ensure /var/lib/ceph/bootstrap-rbd-mirror exists
+      file:
+        path: /var/lib/ceph/bootstrap-rbd-mirror
+        state: directory
+        owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
+        group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
+
     - name: copy ceph key(s)
       copy:
         dest: "/var/lib/ceph/bootstrap-rbd-mirror/{{ cluster }}.keyring"