Mohammed Naser | 0003fd0 | 2022-03-12 15:38:24 -0500 | [diff] [blame] | 1 | # 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 Naser | 511c3fa | 2022-03-17 17:54:10 -0400 | [diff] [blame] | 21 | ansible.builtin.set_fact: |
guilhermesteinmuller | 4470ee2 | 2022-03-28 19:33:20 -0300 | [diff] [blame] | 22 | ceph_mon_ip_address: "{{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr(ceph_mon_public_network) | first }}" |
Mohammed Naser | 0003fd0 | 2022-03-12 15:38:24 -0500 | [diff] [blame] | 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 }}" |
Mohammed Naser | 511c3fa | 2022-03-17 17:54:10 -0400 | [diff] [blame] | 30 | owner: ceph |
| 31 | group: ceph |
| 32 | mode: 0640 |
Mohammed Naser | 0003fd0 | 2022-03-12 15:38:24 -0500 | [diff] [blame] | 33 | 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 Naser | 511c3fa | 2022-03-17 17:54:10 -0400 | [diff] [blame] | 76 | ansible.builtin.command: ceph auth get mon. -o /tmp/ceph.mon.keyring |
Mohammed Naser | 0003fd0 | 2022-03-12 15:38:24 -0500 | [diff] [blame] | 77 | changed_when: false |
| 78 | when: inventory_hostname != _ceph_mon_bootstrap_node |
| 79 | |
| 80 | - name: get monmap keyring |
Mohammed Naser | 511c3fa | 2022-03-17 17:54:10 -0400 | [diff] [blame] | 81 | ansible.builtin.command: ceph mon getmap -o /tmp/monmap |
Mohammed Naser | 0003fd0 | 2022-03-12 15:38:24 -0500 | [diff] [blame] | 82 | 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 Naser | 511c3fa | 2022-03-17 17:54:10 -0400 | [diff] [blame] | 90 | ansible.builtin.command: ceph mon enable-msgr2 |
Mohammed Naser | 0003fd0 | 2022-03-12 15:38:24 -0500 | [diff] [blame] | 91 | changed_when: false |
| 92 | when: inventory_hostname == _ceph_mon_bootstrap_node |