Skip to content

Commit 0f3128a

Browse files
committed
Initial code commit
1 parent 0d49607 commit 0f3128a

File tree

9 files changed

+231
-0
lines changed

9 files changed

+231
-0
lines changed

defaults/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
cephadm_skip_prechecks: false
3+
# FSID
4+
cephadm_fsid: "4aaf9419-b281-4672-9f6d-2f549ac7c774"
5+
# Recreate cluster
6+
cephadm_recreate: false
7+
# Packages
8+
cephadm_custom_repos: true
9+
# Registry
10+
cephadm_registry_url: ""
11+
cephadm_registry_username: ""
12+
cephadm_registry_password: ""
13+
# Bootstrap settings
14+
cephadm_enable_dashboard: false
15+
cephadm_enable_firewalld: false
16+
cephadm_enable_monitoring: false
17+
cephadm_install_ceph_cli: false
18+
cephadm_ssh_public_key: "/etc/ceph/cephadm.pub"
19+
cephadm_ssh_private_key: "/etc/ceph/cephadm.id"
20+
# Networking
21+
cephadm_public_interface: "{{ storage_net_interface }}"
22+
cephadm_cluster_interface: "{{ storage_mgmt_net_interface }}"
23+
cephadm_public_network: "{{ storage_net_cidr }}"
24+
cephadm_cluster_network: "{{ storage_mgmt_net_cidr }}"
25+
# OSDs
26+
cephadm_osd_devices: []

tasks/bootstrap.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
- name: Bootstrap cephadm
3+
block:
4+
- name: Template out cluster.yml
5+
template:
6+
src: "templates/cluster.yml.j2"
7+
dest: "/tmp/cephadm_cluster.yml"
8+
become: true
9+
run_once: True
10+
11+
- name: Bootstrap cephadm
12+
vars:
13+
mon_ip: "{{ hostvars[inventory_hostname]['ansible_'~cephadm_public_interface].ipv4.address }}"
14+
monitoring_stack: "{{ '--skip-monitoring-stack' if not (cephadm_enable_monitoring | bool) else '' }}"
15+
dashboard: "{{ '--skip-dashboard' if not cephadm_enable_dashboard | bool else '' }}"
16+
firewalld: "{{ '--skip-firewalld' if not cephadm_enable_firewalld | bool else '' }}"
17+
command:
18+
cmd: >
19+
cephadm bootstrap
20+
{{ monitoring_stack }}
21+
{{ dashboard }}
22+
{{ firewalld }}
23+
--ssh-private-key={{ cephadm_ssh_private_key }}
24+
--ssh-public-key={{ cephadm_ssh_public_key }}
25+
{% if cephadm_registry_url | length > 0 %}
26+
--registry-url={{ cephadm_registry_url }}
27+
--registry-username={{ cephadm_registry_username }}
28+
--registry-password={{ cephadm_registry_password }}
29+
{% endif %}
30+
--skip-pull
31+
--fsid={{ cephadm_fsid }}
32+
--mon-ip={{ mon_ip }}
33+
become: true
34+
when: not cephadm_check_ceph_conf.stat.exists
35+
36+
- name: Set public network
37+
command:
38+
cmd: "cephadm shell -- ceph config set global public_network {{ cephadm_public_network }}"
39+
become: true
40+
41+
- name: Set cluster network
42+
command:
43+
cmd: "cephadm shell -- ceph config set global cluster_network {{ cephadm_cluster_network }}"
44+
when: cephadm_cluster_network | length > 0
45+
become: true
46+
47+
- name: Template out cluster.yml
48+
template:
49+
src: "templates/cluster.yml.j2"
50+
dest: "/var/run/ceph/{{ cephadm_fsid }}/cephadm_cluster.yml"
51+
become: true
52+
run_once: True
53+
54+
- name: Apply spec
55+
command:
56+
cmd: >
57+
cephadm shell --
58+
ceph orch apply -i /var/run/ceph/cephadm_cluster.yml
59+
become: true
60+
61+
- name: Install ceph cli on mon hosts
62+
command:
63+
cmd: "cephadm install ceph"
64+
become: true
65+
when: cephadm_install_ceph_cli
66+
67+
- name: Add OSDs
68+
command:
69+
cmd: "cephadm daemon add osd {{ ansible_hostname }}:{{ item }}"
70+
become: true
71+
when: cephadm_osd_devices | length > 0
72+
with_items: "{{ cephadm_osd_devices }}"
73+
74+
delegate_to: "{{ groups['mons'][0] }}"
75+
run_once: True

tasks/destroy.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
- name: Get Ceph FSID
3+
command:
4+
cmd: "cephadm shell -- ceph fsid"
5+
become: true
6+
register: cephadm_destroy_fsid
7+
delegate_to: "{{ groups['mons'][0] }}"
8+
run_once: True
9+
changed_when: false
10+
failed_when: false
11+
12+
- name: Destroy cluster
13+
command:
14+
cmd: "cephadm rm-cluster --fsid {{ cephadm_destroy_fsid.stdout }} --force"
15+
become: true
16+
when: cephadm_destroy_fsid.rc != 1
17+
18+
- name: Remove ssh keys
19+
file:
20+
path: "{{ item }}"
21+
state: absent
22+
with_items:
23+
- "{{ cephadm_ssh_private_key }}"
24+
- "{{ cephadm_ssh_public_key }}"
25+
become: true

tasks/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- include_tasks: "destroy.yml"
3+
when: cephadm_recreate | bool
4+
5+
- include_tasks: "prechecks.yml"
6+
when: not cephadm_skip_prechecks | bool
7+
- include_tasks: "prereqs.yml"
8+
- include_tasks: "bootstrap.yml"
9+
when: cephadm_bootstrap | bool
10+
- include_tasks: "osds.yml"

tasks/openstack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

tasks/osds.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Add OSDs
3+
vars:
4+
ansible_host: "{{ hostvars[cephadm_host].ansible_host | default(cephadm_host) }}"
5+
command:
6+
cmd: "cephadm shell -- ceph orch daemon add osd {{ inventory_hostname }}:{{ item }}"
7+
become: true
8+
when: cephadm_osd_devices | length > 0
9+
with_items: "{{ cephadm_osd_devices }}"
10+
delegate_to: "{{ cephadm_host }}"

tasks/prechecks.yml

Whitespace-only changes.

tasks/prereqs.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
- name: Install centos-release-ceph-octopus package
3+
dnf:
4+
name: "centos-release-ceph-octopus"
5+
state: present
6+
when: not cephadm_custom_repos | bool
7+
become: true
8+
9+
- name: Install cephadm package
10+
dnf:
11+
name: "cephadm"
12+
state: present
13+
become: true
14+
15+
- name: Prepare cephadm bootstrap dependencies
16+
block:
17+
- name: Ensure /etc/ceph directory exists
18+
file:
19+
path: /etc/ceph
20+
state: directory
21+
become: true
22+
23+
- name: Check if /etc/ceph/ceph.conf exists
24+
stat:
25+
path: /etc/ceph/ceph.conf
26+
register: cephadm_check_ceph_conf
27+
28+
- name: Check if cephadm ssh key exists
29+
stat:
30+
path: "{{ cephadm_ssh_private_key }}"
31+
register: cephadm_check_ceph_id
32+
33+
- name: Generate ssh key for cephadm
34+
openssh_keypair:
35+
path: "{{ cephadm_ssh_private_key }}"
36+
size: 4096
37+
comment: "ceph-{{ cephadm_fsid }}"
38+
when: not cephadm_check_ceph_id.stat.exists
39+
register: cephadm_ssh_key
40+
become: true
41+
42+
- name: Save public key
43+
copy:
44+
content: "{{ cephadm_ssh_key.public_key }}"
45+
dest: "{{ cephadm_ssh_public_key }}"
46+
become: true
47+
when: not cephadm_check_ceph_id.stat.exists
48+
delegate_to: "{{ groups['mons'][0] }}"
49+
run_once: True
50+
51+
- name: Copy cephadm public key to all hosts
52+
authorized_key:
53+
user: root
54+
state: present
55+
key: "{{ cephadm_ssh_key.public_key }}"
56+
become: true
57+
when: not cephadm_check_ceph_id.stat.exists

templates/cluster.yml.j2

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
service_type: mon
3+
placement:
4+
label: "mon"
5+
---
6+
service_type: mgr
7+
placement:
8+
label: "mgr"
9+
---
10+
service_type: crash
11+
placement:
12+
host_pattern: "*"
13+
{% for host in groups['mons'] %}
14+
---
15+
service_type: host
16+
hostname: {{ host }}
17+
labels:
18+
- mon
19+
- mgr
20+
{% endfor %}
21+
{% for host in groups['osds'] %}
22+
---
23+
service_type: host
24+
hostname: {{ host }}
25+
labels:
26+
- osd
27+
{% endfor %}

0 commit comments

Comments
 (0)