blob: 90cdfc26e74d4eadf5eadbeacdb52158ea2bd2ba [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
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
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 }}"
Mohammed Naser511c3fa2022-03-17 17:54:10 -040030 owner: ceph
31 group: ceph
32 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
43- name: check if any node is bootstrapped
44 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
50- name: select pre-existing bootstrap node if exists
51 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
56- name: bootstrap cluster
57 ansible.builtin.include_tasks: bootstrap-ceph.yml
58 when:
59 - _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | length == 0
60
61- name: grab admin keyring
62 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
68- name: upload client.admin keyring
69 ansible.builtin.copy:
70 content: "{{ _ceph_mon_admin_keyring['content'] | b64decode }}"
71 dest: /etc/ceph/ceph.client.admin.keyring
72 mode: 0600
73 when: inventory_hostname != _ceph_mon_bootstrap_node
74
75- 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
80- 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
85- name: start monitor
86 ansible.builtin.include_tasks: start-monitor.yml
87 when: inventory_hostname != _ceph_mon_bootstrap_node
88
89- 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