blob: d4117a026e869905a27baf52df77ba479dfde901 [file] [log] [blame]
# Copyright (c) 2022 VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: install packages
ansible.builtin.apt:
name: ["ceph-mon"]
install_recommends: false
- name: set ceph monitor ip address
set_fact:
ceph_mon_ip_address: "{{ ansible_default_ipv4.address }}"
- name: generate basic configuration file
community.general.ini_file:
path: /etc/ceph/ceph.conf
section: global
option: "{{ item.option }}"
value: "{{ item.value }}"
loop:
- option: fsid
value: "{{ ceph_mon_fsid }}"
- option: mon host
value: "{{ groups[ceph_mon_group] | map('extract', hostvars, ['ceph_mon_ip_address']) | join(',') }}"
- option: public network
value: "{{ ceph_mon_public_network }}"
- option: cluster network
value: "{{ ceph_mon_cluster_network }}"
- name: check if any node is bootstrapped
ansible.builtin.stat:
path: "/var/lib/ceph/mon/ceph-{{ hostvars[item]['inventory_hostname_short'] }}/store.db"
register: _ceph_mon_stat
loop: "{{ groups[ceph_mon_group] }}"
delegate_to: "{{ item }}"
- name: select pre-existing bootstrap node if exists
ansible.builtin.set_fact:
_ceph_mon_bootstrap_node: "{{ _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | map(attribute='item') | first }}"
when:
- _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | length > 0
- name: bootstrap cluster
ansible.builtin.include_tasks: bootstrap-ceph.yml
when:
- _ceph_mon_stat.results | selectattr('stat.exists', 'equalto', true) | length == 0
- name: grab admin keyring
delegate_to: "{{ _ceph_mon_bootstrap_node }}"
ansible.builtin.slurp:
src: /etc/ceph/ceph.client.admin.keyring
register: _ceph_mon_admin_keyring
when: inventory_hostname != _ceph_mon_bootstrap_node
- name: upload client.admin keyring
ansible.builtin.copy:
content: "{{ _ceph_mon_admin_keyring['content'] | b64decode }}"
dest: /etc/ceph/ceph.client.admin.keyring
mode: 0600
when: inventory_hostname != _ceph_mon_bootstrap_node
- name: get monitor keyring
ansible.builtin.shell: ceph auth get mon. -o /tmp/ceph.mon.keyring
changed_when: false
when: inventory_hostname != _ceph_mon_bootstrap_node
- name: get monmap keyring
ansible.builtin.shell: ceph mon getmap -o /tmp/monmap
changed_when: false
when: inventory_hostname != _ceph_mon_bootstrap_node
- name: start monitor
ansible.builtin.include_tasks: start-monitor.yml
when: inventory_hostname != _ceph_mon_bootstrap_node
- name: enable msgr2
ansible.builtin.shell: ceph mon enable-msgr2
changed_when: false
when: inventory_hostname == _ceph_mon_bootstrap_node