From 736285cdbec11c67a9e6a813065214ac2007b15c Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Thu, 10 Jun 2021 16:28:21 +0200 Subject: [PATCH] Deploy rbd-mirror using cephadm This patch enables the support of the rbd-mirror deployment via the spec. The approach is the same used for the other daemons and when the OS::TripleO::Services::CephRbdMirror is included in a TripleO role, the rbd-mirror tasks are executed (the spec is built and applied against the Ceph cluster using the ceph_mkspec module). Change-Id: I0d1ce33270ccf8636925c3534812c3b1cf650103 (cherry picked from commit 9b6e8a67b5994d12b931fb34e221b4223584b038) --- .../ansible_plugins/modules/ceph_mkspec.py | 2 +- tripleo_ansible/playbooks/cephadm.yml | 5 ++ .../roles/tripleo_cephadm/defaults/main.yml | 3 + .../roles/tripleo_cephadm/tasks/ceph_cli.yaml | 2 +- .../tripleo_cephadm/tasks/rbd_mirror.yaml | 75 +++++++++++++++++++ .../tripleo_run_cephadm/tasks/prepare.yml | 1 + 6 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 tripleo_ansible/roles/tripleo_cephadm/tasks/rbd_mirror.yaml diff --git a/tripleo_ansible/ansible_plugins/modules/ceph_mkspec.py b/tripleo_ansible/ansible_plugins/modules/ceph_mkspec.py index 7f617df55..1d0fdaad4 100644 --- a/tripleo_ansible/ansible_plugins/modules/ceph_mkspec.py +++ b/tripleo_ansible/ansible_plugins/modules/ceph_mkspec.py @@ -64,7 +64,7 @@ options: - The Ceph daemon that is going to be applied required: true type: str - choices: ['host', 'mon', 'osd', 'mds', 'rgw', 'nfs', 'node-exporter', 'prometheus', 'alertmanager', 'grafana'] + choices: ['host', 'mon', 'osd', 'mds', 'rgw', 'nfs', 'node-exporter', 'prometheus', 'alertmanager', 'grafana', 'rbd-mirror'] service_id: description: - The ID associated to the Ceph daemon diff --git a/tripleo_ansible/playbooks/cephadm.yml b/tripleo_ansible/playbooks/cephadm.yml index c2100b54a..cccec6c18 100644 --- a/tripleo_ansible/playbooks/cephadm.yml +++ b/tripleo_ansible/playbooks/cephadm.yml @@ -73,6 +73,11 @@ name: tripleo_cephadm tasks_from: keys + - name: Configure RBD Mirror + import_role: + name: tripleo_cephadm + tasks_from: rbd_mirror + - name: Export configuration for tripleo_ceph_client import_role: name: tripleo_cephadm diff --git a/tripleo_ansible/roles/tripleo_cephadm/defaults/main.yml b/tripleo_ansible/roles/tripleo_cephadm/defaults/main.yml index 1c234c099..9b48659c7 100644 --- a/tripleo_ansible/roles/tripleo_cephadm/defaults/main.yml +++ b/tripleo_ansible/roles/tripleo_cephadm/defaults/main.yml @@ -52,3 +52,6 @@ tripleo_cephadm_ceph_nfs_rados_backend: true tripleo_cephadm_certs: /etc/pki/tls tripleo_cephadm_idmap_conf: "/etc/ganesha/idmap.conf" tripleo_cephadm_idmap_overrides: {} +tripleo_cephadm_rbd_mirror_pool: '' +tripleo_cephadm_rbd_mirror_remote_cluster: not-ceph +tripleo_cephadm_rbd_mirror_remote_user: '' diff --git a/tripleo_ansible/roles/tripleo_cephadm/tasks/ceph_cli.yaml b/tripleo_ansible/roles/tripleo_cephadm/tasks/ceph_cli.yaml index 2d65e9a1d..ac1122ef0 100644 --- a/tripleo_ansible/roles/tripleo_cephadm/tasks/ceph_cli.yaml +++ b/tripleo_ansible/roles/tripleo_cephadm/tasks/ceph_cli.yaml @@ -33,7 +33,7 @@ {% endif %} --entrypoint {{ ceph_command | default('ceph') }} {{ tripleo_cephadm_container_ns }}/{{ tripleo_cephadm_container_image }}:{{ tripleo_cephadm_container_tag }} - {% if ceph_command|default('ceph') == 'ceph' or ceph_command|default('ceph') == 'rados' -%} + {% if ceph_command|default('ceph') == 'ceph' or ceph_command|default('ceph') == 'rados' or ceph_command|default('ceph') == 'rbd' -%} {% if not admin_daemon|default(false) -%} --fsid {{ tripleo_cephadm_fsid }} -c {{ tripleo_cephadm_conf }} -k {{ tripleo_cephadm_keyring_prefix }}.{{ select_keyring| default('admin') }}.keyring {%- endif %} diff --git a/tripleo_ansible/roles/tripleo_cephadm/tasks/rbd_mirror.yaml b/tripleo_ansible/roles/tripleo_cephadm/tasks/rbd_mirror.yaml new file mode 100644 index 000000000..50a4ea551 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_cephadm/tasks/rbd_mirror.yaml @@ -0,0 +1,75 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Deploy the RBD Mirror daemon + block: + # Using two tasks with a boolean due to the ansible bug: https://github.com/ansible/ansible/issues/68364 + - name: Collect the host and build the resulting host list + set_fact: + _hosts: "{{ _hosts|default([]) + [ hostvars[item].canonical_hostname ] }}" + with_items: "{{ groups['ceph_rbdmirror'] }}" + when: tripleo_cephadm_fqdn | bool + + - name: Collect the host and build the resulting host list + set_fact: + _hosts: "{{ _hosts|default([]) + [ hostvars[item].inventory_hostname ] }}" + with_items: "{{ groups['ceph_rbdmirror'] }}" + when: not tripleo_cephadm_fqdn | bool + + - name: Create the RBD Mirror Daemon spec definition + become: true + ceph_mkspec: + service_type: rbd-mirror + apply: true + hosts: "{{ _hosts | unique }}" + render_path: "{{ tripleo_cephadm_spec_home }}" + networks: "{{ radosgw_address_block }}" + register: spc + environment: + CEPH_CONTAINER_IMAGE: "{{ tripleo_cephadm_container_ns + '/' + tripleo_cephadm_container_image + ':' + tripleo_cephadm_container_tag }}" + CEPH_CONTAINER_BINARY: "{{ tripleo_cephadm_container_cli }}" + when: + - tripleo_enabled_services | intersect(['ceph_rbdmirror']) + +- name: Configure RBD mirror + when: tripleo_cephadm_rbd_mirror_pool | default('') | length > 0 + block: + - name: Get ceph_cli + include_tasks: ceph_cli.yaml + vars: + ceph_command: rbd + + - name: enable mirroring on the pool + command: "{{ tripleo_cephadm_ceph_cli }} --cluster {{ tripleo_cephadm_cluster }} mirror pool enable {{ tripleo_cephadm_rbd_mirror_pool }} pool" + register: result + changed_when: false + retries: 90 + delay: 1 + until: result is succeeded + + - name: list mirroring peer + command: "{{ tripleo_cephadm_ceph_cli }} --cluster {{ tripleo_cephadm_cluster }} mirror pool info {{ tripleo_cephadm_rbd_mirror_pool }}" + changed_when: false + register: mirror_peer + + - name: add a mirroring peer + command: "{{ tripleo_cephadm_ceph_cli }} --cluster {{ tripleo_cephadm_cluster }} mirror pool peer add \ + {{ tripleo_cephadm_rbd_mirror_pool }} {{ tripleo_cephadm_rbd_mirror_remote_user }}_{{ tripleo_cephadm_rbd_mirror_remote_cluster }}" + changed_when: false + when: + - tripleo_cephadm_rbd_mirror_remote_user | length > 0 + - tripleo_cephadm_rbd_mirror_remote_cluster | length > 0 + - tripleo_cephadm_rbd_mirror_remote_user not in mirror_peer.stdout diff --git a/tripleo_ansible/roles/tripleo_run_cephadm/tasks/prepare.yml b/tripleo_ansible/roles/tripleo_run_cephadm/tasks/prepare.yml index 0f470c9fe..b87fac4db 100644 --- a/tripleo_ansible/roles/tripleo_run_cephadm/tasks/prepare.yml +++ b/tripleo_ansible/roles/tripleo_run_cephadm/tasks/prepare.yml @@ -77,6 +77,7 @@ content: "{{ cephadm_extra_vars | combine(ceph_overrides|default({})) | combine(ceph_monitoring_stack|default({})) | combine(ceph_dashboard_vars|default({})) + | combine(cephadm_rbdmirror| default({})) | combine(cephadm_rgw_vars|default({})) | combine(cephfs_metadata|default({})) | combine(ceph_nfs_vars|default({}))