blob: d4117a026e869905a27baf52df77ba479dfde901 [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: ["ceph-mon"]
18 install_recommends: false
19
20- name: set ceph monitor ip address
21 set_fact:
22 ceph_mon_ip_address: "{{ ansible_default_ipv4.address }}"
23
24- name: generate basic configuration file
25 community.general.ini_file:
26 path: /etc/ceph/ceph.conf
27 section: global
28 option: "{{ item.option }}"
29 value: "{{ item.value }}"
30 loop:
31 - option: fsid
32 value: "{{ ceph_mon_fsid }}"
33 - option: mon host
34 value: "{{ groups[ceph_mon_group] | map('extract', hostvars, ['ceph_mon_ip_address']) | join(',') }}"
35 - option: public network
36 value: "{{ ceph_mon_public_network }}"
37 - option: cluster network
38 value: "{{ ceph_mon_cluster_network }}"
39
40- name: check if any node is bootstrapped
41 ansible.builtin.stat:
42 path: "/var/lib/ceph/mon/ceph-{{ hostvars[item]['inventory_hostname_short'] }}/store.db"
43 register: _ceph_mon_stat
44 loop: "{{ groups[ceph_mon_group] }}"
45 delegate_to: "{{ item }}"
46
47- name: select pre-existing bootstrap node if exists
48 ansible.builtin.set_fact:
49 _ceph_mon_bootstrap_node: "{{ _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | map(attribute='item') | first }}"
50 when:
51 - _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | length > 0
52
53- name: bootstrap cluster
54 ansible.builtin.include_tasks: bootstrap-ceph.yml
55 when:
56 - _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | length == 0
57
58- name: grab admin keyring
59 delegate_to: "{{ _ceph_mon_bootstrap_node }}"
60 ansible.builtin.slurp:
61 src: /etc/ceph/ceph.client.admin.keyring
62 register: _ceph_mon_admin_keyring
63 when: inventory_hostname != _ceph_mon_bootstrap_node
64
65- name: upload client.admin keyring
66 ansible.builtin.copy:
67 content: "{{ _ceph_mon_admin_keyring['content'] | b64decode }}"
68 dest: /etc/ceph/ceph.client.admin.keyring
69 mode: 0600
70 when: inventory_hostname != _ceph_mon_bootstrap_node
71
72- name: get monitor keyring
73 ansible.builtin.shell: ceph auth get mon. -o /tmp/ceph.mon.keyring
74 changed_when: false
75 when: inventory_hostname != _ceph_mon_bootstrap_node
76
77- name: get monmap keyring
78 ansible.builtin.shell: ceph mon getmap -o /tmp/monmap
79 changed_when: false
80 when: inventory_hostname != _ceph_mon_bootstrap_node
81
82- name: start monitor
83 ansible.builtin.include_tasks: start-monitor.yml
84 when: inventory_hostname != _ceph_mon_bootstrap_node
85
86- name: enable msgr2
87 ansible.builtin.shell: ceph mon enable-msgr2
88 changed_when: false
89 when: inventory_hostname == _ceph_mon_bootstrap_node