aboutsummaryrefslogtreecommitdiff
path: root/roles/cephadm/tasks/main.yml
blob: b0a7180eda583a76d0fc8ab8e9ebbc6fcf2e5d2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
- name: Include package installation
  ansible.builtin.include_tasks: pkg_{{ ansible_os_family | lower }}.yml

- name: Ensure /etc/ceph exists
  ansible.builtin.file:
    path: /etc/ceph
    state: directory
    mode: "0755"
  become: true

- name: Generate ssh key for cephadm
  community.crypto.openssh_keypair:
    path: "/etc/ceph/cephadm.id"
    mode: "0600"
    size: 4096
    comment: "cephadm"
  become: true
  register: cephadm_ssh_key

- name: Save public key
  ansible.builtin.copy:
    content: "{{ cephadm_ssh_key.public_key }}"
    dest: /etc/ceph/cephadm.pub
    mode: "0644"
  become: true

- name: Copy cephadm public key to all hosts
  ansible.posix.authorized_key:
    user: root
    state: present
    key: "{{ cephadm_ssh_key.public_key }}"
  become: true
  with_inventory_hostnames:
    - all
  delegate_to: "{{ item }}"

- name: Bootstrap cephadm
  vars:
    mon_ip: "{{ hostvars[inventory_hostname]['ansible_' + api_interface_name | replace('-', '_')].ipv4.address }}"
  ansible.builtin.command:
    cmd: >
         cephadm
         --docker
         bootstrap
         --ssh-private-key=/etc/ceph/cephadm.id
         --ssh-public-key=/etc/ceph/cephadm.pub
         --skip-monitoring-stack
         --skip-dashboard
         --skip-firewalld
         --log-to-file
         --mon-ip {{ mon_ip }}
  become: true
  changed_when: true
  register: cephadm_bootstrap_output

- name: Get ceph fsid
  vars:
    regexp: 'Cluster fsid: (.*)'
  ansible.builtin.set_fact:
    ceph_fsid: "{{ cephadm_bootstrap_output.stdout | regex_search(regexp, '\\1') | first }}"

- name: Template out cluster spec
  ansible.builtin.template:
    src: templates/cephadm.yml.j2
    dest: "/var/run/ceph/{{ ceph_fsid }}/cluster.yml"
    mode: "0600"
  become: true

- name: Template out command spec
  ansible.builtin.template:
    src: templates/commands.sh.j2
    dest: "/var/run/ceph/{{ ceph_fsid }}/commands.sh"
    mode: "0600"
  become: true

- name: Run commands
  ansible.builtin.command:
    cmd: >
         cephadm shell --
         bash -x /var/run/ceph/commands.sh
  become: true
  changed_when: true

# TODO(mnasiadka): Fix merge_configs to support tabs
- name: Generate ceph.conf without tabs
  vars:
    _mon_host: >-
      {%- set ns = namespace(mon_host=[]) -%}
      {%- for host in groups['all'] -%}
      {%- set current_mon_host = hostvars[host]['ansible_' + api_interface_name | replace('-', '_')].ipv4.address -%}
      {%- set ns.mon_host = ns.mon_host + [current_mon_host] -%}
      {%- endfor -%}
      {{ ns.mon_host }}
    ceph_conf_fixed: |
      [global]
      fsid = {{ ceph_fsid }}
      mon_host = {{ _mon_host | join(", ") }}
  ansible.builtin.copy:
    content: "{{ ceph_conf_fixed }}"
    dest: "/etc/ceph/ceph.conf.fixed"
    mode: "0644"
  become: true