blob: e67a6b67521f467563a3cc6a5208faffb39a86db [file] [log] [blame]
Mohammed Naser0003fd02022-03-12 15:38:24 -05001# Copyright (c) 2022 VEXXHOST, Inc.
2#
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
15- name: install packages
16 ansible.builtin.apt:
17 name: ["udev", "ceph-osd"]
18 install_recommends: false
19
20- name: grab ceph fsid from monitors
21 delegate_to: "{{ groups[ceph_osd_mons_group][0] }}"
22 register: _ceph_fsid
23 changed_when: false
Mohammed Naser511c3fa2022-03-17 17:54:10 -040024 ansible.builtin.command: ceph fsid
Mohammed Naser0003fd02022-03-12 15:38:24 -050025
guilhermesteinmuller48fb5bb2022-03-29 15:31:26 -030026- name: Collect "ceph mon dump" output from a monitor
27 delegate_to: "{{ groups[ceph_osd_mons_group][0] }}"
28 run_once: true
29 ansible.builtin.command: ceph mon dump -f json
30 changed_when: false
31 register: _ceph_mon_dump
32
33- name: Generate fact with list of Ceph monitors
34 run_once: true
35 ansible.builtin.set_fact:
36 ceph_monitors: "{{ _ceph_mon_dump.stdout | from_json | community.general.json_query('mons[*].addr') | map('regex_replace', '(.*):(.*)', '\\1') }}"
Mohammed Naser0003fd02022-03-12 15:38:24 -050037
38- name: generate basic configuration file
39 community.general.ini_file:
40 path: /etc/ceph/ceph.conf
41 section: global
42 option: "{{ item.option }}"
43 value: "{{ item.value }}"
Mohammed Naser511c3fa2022-03-17 17:54:10 -040044 owner: ceph
45 group: ceph
46 mode: 0640
Mohammed Naser0003fd02022-03-12 15:38:24 -050047 loop:
48 - option: fsid
49 value: "{{ _ceph_fsid.stdout | trim }}"
50 - option: mon host
guilhermesteinmuller48fb5bb2022-03-29 15:31:26 -030051 value: "{{ ceph_monitors | join(',') }}"
Mohammed Naser0003fd02022-03-12 15:38:24 -050052
53- name: grab bootstrap-osd from monitors
54 delegate_to: "{{ groups[ceph_osd_mons_group][0] }}"
55 register: _ceph_bootstrap_osd_keyring
56 changed_when: false
Mohammed Naser511c3fa2022-03-17 17:54:10 -040057 ansible.builtin.command: ceph auth get client.bootstrap-osd
Mohammed Naser0003fd02022-03-12 15:38:24 -050058
59- name: install bootstrap-osd keyring
60 ansible.builtin.copy:
61 content: "{{ _ceph_bootstrap_osd_keyring.stdout }}\n"
62 dest: /var/lib/ceph/bootstrap-osd/ceph.keyring
Mohammed Naser511c3fa2022-03-17 17:54:10 -040063 owner: ceph
64 group: ceph
65 mode: 0640
Mohammed Naser0003fd02022-03-12 15:38:24 -050066
67- name: workaround to allow usage of loop devices
68 ansible.builtin.replace:
69 path: /usr/lib/python3/dist-packages/ceph_volume/util/disk.py
70 regexp: "'mpath']"
71 replace: "'mpath', 'loop']"
Mohammed Naser511c3fa2022-03-17 17:54:10 -040072 owner: ceph
73 group: ceph
74 mode: 0640
Mohammed Naser0003fd02022-03-12 15:38:24 -050075 when: molecule | default(false)
76
77# NOTE(mnaser): https://bugs.launchpad.net/ubuntu/+source/ceph/+bug/1917414/comments/30
78- name: workaround for aarch64 systems
79 community.general.ini_file:
80 path: /lib/systemd/system/ceph-osd@.service
81 section: Service
82 option: MemoryDenyWriteExecute
83 value: false
Mohammed Naser511c3fa2022-03-17 17:54:10 -040084 owner: ceph
85 group: ceph
86 mode: 0644
Mohammed Naser0003fd02022-03-12 15:38:24 -050087 register: _ceph_aarch64_fix
88 when: ansible_architecture == 'aarch64'
89
90- name: reload systemd
91 ansible.builtin.service:
92 daemon_reload: "{{ _ceph_aarch64_fix.changed }}"
93
94- name: get which devices don't contain osds
95 register: _ceph_osd_check
96 failed_when: false
97 changed_when: false
98 ansible.builtin.command: /usr/sbin/ceph-volume lvm list {{ item }}
99 loop: "{{ ceph_osd_devices }}"
100
101- name: create osds for volumes which are not setup
Mohammed Naser511c3fa2022-03-17 17:54:10 -0400102 changed_when: true
Mohammed Naser0003fd02022-03-12 15:38:24 -0500103 ansible.builtin.command: /usr/sbin/ceph-volume lvm create --data {{ item }}
104 loop: "{{ _ceph_osd_check.results | selectattr('rc', 'equalto', 1) | map(attribute='item') }}"