blob: 5ce89e23c12ebd05d468099508daf97c1081da97 [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
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020015- name: Install packages
Mohammed Naser0003fd02022-03-12 15:38:24 -050016 ansible.builtin.apt:
17 name: ["ceph-mon"]
18 install_recommends: false
19
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020020- name: Set ceph monitor ip address
Mohammed Naser511c3fa2022-03-17 17:54:10 -040021 ansible.builtin.set_fact:
guilhermesteinmuller4470ee22022-03-28 19:33:20 -030022 ceph_mon_ip_address: "{{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr(ceph_mon_public_network) | first }}"
Mohammed Naser0003fd02022-03-12 15:38:24 -050023
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020024- name: Generate basic configuration file
Mohammed Naser0003fd02022-03-12 15:38:24 -050025 community.general.ini_file:
26 path: /etc/ceph/ceph.conf
27 section: global
28 option: "{{ item.option }}"
29 value: "{{ item.value }}"
Mohammed Naser511c3fa2022-03-17 17:54:10 -040030 owner: ceph
31 group: ceph
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020032 mode: "0640"
Mohammed Naser0003fd02022-03-12 15:38:24 -050033 loop:
34 - option: fsid
35 value: "{{ ceph_mon_fsid }}"
36 - option: mon host
37 value: "{{ groups[ceph_mon_group] | map('extract', hostvars, ['ceph_mon_ip_address']) | join(',') }}"
38 - option: public network
39 value: "{{ ceph_mon_public_network }}"
40 - option: cluster network
41 value: "{{ ceph_mon_cluster_network }}"
42
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020043- name: Check if any node is bootstrapped
Mohammed Naser0003fd02022-03-12 15:38:24 -050044 ansible.builtin.stat:
45 path: "/var/lib/ceph/mon/ceph-{{ hostvars[item]['inventory_hostname_short'] }}/store.db"
46 register: _ceph_mon_stat
47 loop: "{{ groups[ceph_mon_group] }}"
48 delegate_to: "{{ item }}"
49
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020050- name: Select pre-existing bootstrap node if exists
Mohammed Naser0003fd02022-03-12 15:38:24 -050051 ansible.builtin.set_fact:
52 _ceph_mon_bootstrap_node: "{{ _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | map(attribute='item') | first }}"
53 when:
54 - _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | length > 0
55
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020056- name: Bootstrap cluster
Mohammed Naser0003fd02022-03-12 15:38:24 -050057 ansible.builtin.include_tasks: bootstrap-ceph.yml
58 when:
59 - _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | length == 0
60
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020061- name: Grab admin keyring
Mohammed Naser0003fd02022-03-12 15:38:24 -050062 delegate_to: "{{ _ceph_mon_bootstrap_node }}"
63 ansible.builtin.slurp:
64 src: /etc/ceph/ceph.client.admin.keyring
65 register: _ceph_mon_admin_keyring
66 when: inventory_hostname != _ceph_mon_bootstrap_node
67
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020068- name: Upload client.admin keyring
Mohammed Naser0003fd02022-03-12 15:38:24 -050069 ansible.builtin.copy:
70 content: "{{ _ceph_mon_admin_keyring['content'] | b64decode }}"
71 dest: /etc/ceph/ceph.client.admin.keyring
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020072 mode: "0600"
Mohammed Naser0003fd02022-03-12 15:38:24 -050073 when: inventory_hostname != _ceph_mon_bootstrap_node
74
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020075- name: Get monitor keyring
Mohammed Naser511c3fa2022-03-17 17:54:10 -040076 ansible.builtin.command: ceph auth get mon. -o /tmp/ceph.mon.keyring
Mohammed Naser0003fd02022-03-12 15:38:24 -050077 changed_when: false
78 when: inventory_hostname != _ceph_mon_bootstrap_node
79
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020080- name: Get monmap keyring
Mohammed Naser511c3fa2022-03-17 17:54:10 -040081 ansible.builtin.command: ceph mon getmap -o /tmp/monmap
Mohammed Naser0003fd02022-03-12 15:38:24 -050082 changed_when: false
83 when: inventory_hostname != _ceph_mon_bootstrap_node
84
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020085- name: Start monitor
Mohammed Naser0003fd02022-03-12 15:38:24 -050086 ansible.builtin.include_tasks: start-monitor.yml
87 when: inventory_hostname != _ceph_mon_bootstrap_node
88
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020089- name: Enable "msgr2"
Mohammed Naser511c3fa2022-03-17 17:54:10 -040090 ansible.builtin.command: ceph mon enable-msgr2
Mohammed Naser0003fd02022-03-12 15:38:24 -050091 changed_when: false
92 when: inventory_hostname == _ceph_mon_bootstrap_node