blob: 213aee7972b0e0d3aa994ad8a7ee436bffc7c668 [file] [log] [blame]
Mohammed Naser90f91b32023-01-16 22:59:52 +00001# Copyright (c) 2023 VEXXHOST, Inc.
Mohammed Naserb7b97d62022-03-12 16:30:00 -05002#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
guilhermesteinmullerd946d7a2022-04-04 15:04:27 -030015- name: Collect "ceph mon dump" output from a monitor
16 delegate_to: "{{ groups[ceph_csi_rbd_mons_group][0] }}"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050017 run_once: true
Rico Line7132672024-02-28 00:10:53 +080018 ansible.builtin.command: cephadm shell -- ceph mon dump -f json
guilhermesteinmullerd946d7a2022-04-04 15:04:27 -030019 changed_when: false
20 register: _ceph_mon_dump
21
22- name: Generate fact with list of Ceph monitors
23 run_once: true
24 ansible.builtin.set_fact:
Mohammed Naser545bc432023-04-16 23:02:23 +000025 ceph_csi_rbd_ceph_fsid: "{{ _ceph_mon_dump.stdout | from_json | community.general.json_query('fsid') }}"
guilhermesteinmullerd946d7a2022-04-04 15:04:27 -030026 ceph_monitors: "{{ _ceph_mon_dump.stdout | from_json | community.general.json_query('mons[*].addr') | map('regex_replace', '(.*):(.*)', '\\1') }}"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050027
Mohammed Naser511c3fa2022-03-17 17:54:10 -040028- name: Create Ceph pool
Mohammed Naser63b739d2022-05-19 21:51:31 -040029 delegate_to: "{{ groups[ceph_csi_rbd_mons_group][0] }}"
Mohammed Naser90f91b32023-01-16 22:59:52 +000030 run_once: true
Mohammed Naser545bc432023-04-16 23:02:23 +000031 vexxhost.ceph.pool:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050032 name: "{{ ceph_csi_rbd_pool }}"
Mohammed Naser63b739d2022-05-19 21:51:31 -040033 rule_name: "{{ ceph_csi_rbd_rule_name | default(omit) }}"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050034 application: rbd
Mohammed Naser511c3fa2022-03-17 17:54:10 -040035 pg_autoscale_mode: "on"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050036
Mohammed Naser4b24d9b2022-11-02 13:14:52 -040037- name: Create user {{ ceph_csi_rbd_user }}
Mohammed Naser63b739d2022-05-19 21:51:31 -040038 delegate_to: "{{ groups[ceph_csi_rbd_mons_group][0] }}"
Mohammed Naser90f91b32023-01-16 22:59:52 +000039 run_once: true
Mohammed Naser545bc432023-04-16 23:02:23 +000040 vexxhost.ceph.key:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050041 name: "{{ ceph_csi_rbd_user }}"
42 caps:
43 mon: profile rbd
44 mgr: profile rbd pool={{ ceph_csi_rbd_pool }}
45 osd: profile rbd pool={{ ceph_csi_rbd_pool }}
46
Mohammed Naser4b24d9b2022-11-02 13:14:52 -040047- name: Retrieve keyring for {{ ceph_csi_rbd_user }}
Mohammed Naser63b739d2022-05-19 21:51:31 -040048 delegate_to: "{{ groups[ceph_csi_rbd_mons_group][0] }}"
Mohammed Naser90f91b32023-01-16 22:59:52 +000049 run_once: true
Mohammed Naser545bc432023-04-16 23:02:23 +000050 vexxhost.ceph.key:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050051 name: "{{ ceph_csi_rbd_user }}"
52 state: info
53 output_format: json
54 register: _ceph_key
55
Mohammed Naser511c3fa2022-03-17 17:54:10 -040056- name: Store keyring inside fact
Mohammed Naser90f91b32023-01-16 22:59:52 +000057 run_once: true
Mohammed Naser511c3fa2022-03-17 17:54:10 -040058 ansible.builtin.set_fact:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050059 _ceph_rbd_csi_ceph_keyring: "{{ _ceph_key.stdout | from_json | first }}"
60
Mohammed Naser90f91b32023-01-16 22:59:52 +000061# NOTE(mnaser): We should get rid of this task eventually as it is suspending
62# the old HelmRelease and removing it to avoid uninstalling the
63# Helm chart.
64- name: Uninstall the legacy HelmRelease
65 run_once: true
66 block:
67 - name: Suspend the existing HelmRelease
Mohammed Naserf0314a82023-04-11 18:53:30 +000068 failed_when: false
Mohammed Naser90f91b32023-01-16 22:59:52 +000069 kubernetes.core.k8s:
70 state: patched
71 api_version: helm.toolkit.fluxcd.io/v2beta1
Mohammed Naserc8e1a452022-08-11 16:16:13 -040072 kind: HelmRelease
Mohammed Naser90f91b32023-01-16 22:59:52 +000073 name: "{{ ceph_csi_rbd_helm_release_name }}"
74 namespace: "{{ ceph_csi_rbd_helm_release_namespace }}"
75 definition:
76 spec:
77 suspend: true
78
79 - name: Remove the existing HelmRelease
Mohammed Naserf0314a82023-04-11 18:53:30 +000080 failed_when: false
Mohammed Naser90f91b32023-01-16 22:59:52 +000081 kubernetes.core.k8s:
82 state: absent
83 api_version: helm.toolkit.fluxcd.io/v2beta1
84 kind: HelmRelease
85 name: "{{ ceph_csi_rbd_helm_release_name }}"
86 namespace: "{{ ceph_csi_rbd_helm_release_namespace }}"
87
88- name: Deploy Helm chart
89 run_once: true
90 kubernetes.core.helm:
91 name: "{{ ceph_csi_rbd_helm_release_name }}"
92 chart_ref: "{{ ceph_csi_rbd_helm_chart_ref }}"
93 release_namespace: "{{ ceph_csi_rbd_helm_release_namespace }}"
94 create_namespace: true
95 kubeconfig: /etc/kubernetes/admin.conf
96 values: "{{ _ceph_csi_rbd_helm_values | combine(ceph_csi_rbd_helm_values, recursive=True) }}"