blob: 04826e50b6fd51a8392833ffa5da973054920640 [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
guilhermesteinmullerd946d7a2022-04-04 15:04:27 -030018 ansible.builtin.command: ceph mon dump -f json
19 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:
25 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 -050026
Mohammed Naser511c3fa2022-03-17 17:54:10 -040027- name: Create Ceph pool
Mohammed Naser63b739d2022-05-19 21:51:31 -040028 delegate_to: "{{ groups[ceph_csi_rbd_mons_group][0] }}"
Mohammed Naser90f91b32023-01-16 22:59:52 +000029 run_once: true
Mohammed Naser511c3fa2022-03-17 17:54:10 -040030 vexxhost.atmosphere.ceph_pool:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050031 name: "{{ ceph_csi_rbd_pool }}"
Mohammed Naser63b739d2022-05-19 21:51:31 -040032 rule_name: "{{ ceph_csi_rbd_rule_name | default(omit) }}"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050033 application: rbd
Mohammed Naser511c3fa2022-03-17 17:54:10 -040034 pg_autoscale_mode: "on"
Mohammed Naserb7b97d62022-03-12 16:30:00 -050035
Mohammed Naser4b24d9b2022-11-02 13:14:52 -040036- name: Create user {{ ceph_csi_rbd_user }}
Mohammed Naser63b739d2022-05-19 21:51:31 -040037 delegate_to: "{{ groups[ceph_csi_rbd_mons_group][0] }}"
Mohammed Naser90f91b32023-01-16 22:59:52 +000038 run_once: true
Mohammed Naser511c3fa2022-03-17 17:54:10 -040039 vexxhost.atmosphere.ceph_key:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050040 name: "{{ ceph_csi_rbd_user }}"
41 caps:
42 mon: profile rbd
43 mgr: profile rbd pool={{ ceph_csi_rbd_pool }}
44 osd: profile rbd pool={{ ceph_csi_rbd_pool }}
45
Mohammed Naser4b24d9b2022-11-02 13:14:52 -040046- name: Retrieve keyring for {{ ceph_csi_rbd_user }}
Mohammed Naser63b739d2022-05-19 21:51:31 -040047 delegate_to: "{{ groups[ceph_csi_rbd_mons_group][0] }}"
Mohammed Naser90f91b32023-01-16 22:59:52 +000048 run_once: true
Mohammed Naser511c3fa2022-03-17 17:54:10 -040049 vexxhost.atmosphere.ceph_key:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050050 name: "{{ ceph_csi_rbd_user }}"
51 state: info
52 output_format: json
53 register: _ceph_key
54
Mohammed Naser511c3fa2022-03-17 17:54:10 -040055- name: Store keyring inside fact
Mohammed Naser90f91b32023-01-16 22:59:52 +000056 run_once: true
Mohammed Naser511c3fa2022-03-17 17:54:10 -040057 ansible.builtin.set_fact:
Mohammed Naserb7b97d62022-03-12 16:30:00 -050058 _ceph_rbd_csi_ceph_keyring: "{{ _ceph_key.stdout | from_json | first }}"
59
Mohammed Naser90f91b32023-01-16 22:59:52 +000060# NOTE(mnaser): We should get rid of this task eventually as it is suspending
61# the old HelmRelease and removing it to avoid uninstalling the
62# Helm chart.
63- name: Uninstall the legacy HelmRelease
64 run_once: true
65 block:
66 - name: Suspend the existing HelmRelease
67 kubernetes.core.k8s:
68 state: patched
69 api_version: helm.toolkit.fluxcd.io/v2beta1
Mohammed Naserc8e1a452022-08-11 16:16:13 -040070 kind: HelmRelease
Mohammed Naser90f91b32023-01-16 22:59:52 +000071 name: "{{ ceph_csi_rbd_helm_release_name }}"
72 namespace: "{{ ceph_csi_rbd_helm_release_namespace }}"
73 definition:
74 spec:
75 suspend: true
76
77 - name: Remove the existing HelmRelease
78 kubernetes.core.k8s:
79 state: absent
80 api_version: helm.toolkit.fluxcd.io/v2beta1
81 kind: HelmRelease
82 name: "{{ ceph_csi_rbd_helm_release_name }}"
83 namespace: "{{ ceph_csi_rbd_helm_release_namespace }}"
84
85- name: Deploy Helm chart
86 run_once: true
87 kubernetes.core.helm:
88 name: "{{ ceph_csi_rbd_helm_release_name }}"
89 chart_ref: "{{ ceph_csi_rbd_helm_chart_ref }}"
90 release_namespace: "{{ ceph_csi_rbd_helm_release_namespace }}"
91 create_namespace: true
92 kubeconfig: /etc/kubernetes/admin.conf
93 values: "{{ _ceph_csi_rbd_helm_values | combine(ceph_csi_rbd_helm_values, recursive=True) }}"