Skip to content

Instantly share code, notes, and snippets.

@mtelvers
Created November 3, 2025 17:51
Show Gist options
  • Select an option

  • Save mtelvers/15e8bb0328aca66520ebe1351572a7d3 to your computer and use it in GitHub Desktop.

Select an option

Save mtelvers/15e8bb0328aca66520ebe1351572a7d3 to your computer and use it in GitHub Desktop.
Deploy CephFS
---
- name: Configure Hostnames
hosts: ceph
tasks:
- name: Set hostname to inventory name
hostname:
name: "{{ inventory_hostname }}"
- name: Deploy Ceph Master
hosts: ceph_master
tasks:
- name: Install cephadm on master
apt:
name: cephadm
state: present
update_cache: yes
- name: Bootstrap Ceph cluster
command: cephadm bootstrap --mon-ip {{ ansible_host }}
register: ceph_bootstrap_output
- name: Display bootstrap output (contains initial password)
debug:
var: ceph_bootstrap_output.stdout_lines
- name: Fetch Ceph public key from master
fetch:
src: /etc/ceph/ceph.pub
dest: /tmp/ceph.pub
flat: yes
- name: Deploy Ceph Nodes
hosts: ceph_nodes
tasks:
- name: Install packages on worker nodes
apt:
name:
- docker.io
- cephadm
state: present
update_cache: yes
- name: Add Ceph public key to authorized_keys
authorized_key:
user: root
key: "{{ lookup('file', '/tmp/ceph.pub') }}"
state: present
- name: Add Worker Nodes to Ceph Cluster
hosts: ceph_master
tasks:
- name: Add worker nodes to Ceph orchestrator
command: cephadm shell -- ceph orch host add {{ item }} {{ hostvars[item]['ansible_host'] }} --labels=_admin
loop: "{{ groups['ceph_nodes'] }}"
- name: Get Bootstrap OSD Keyring
hosts: ceph_master
tasks:
- name: Get bootstrap-osd keyring from master (base64 encoded)
shell: cephadm shell -- bash -c "ceph auth get client.bootstrap-osd | base64 --wrap=0"
register: bootstrap_keyring
- name: Configure All Ceph Nodes
hosts: ceph
tasks:
- name: Prepare raw volumes on all nodes
shell: |
cephadm shell -- bash -c "mkdir -p /var/lib/ceph/bootstrap-osd && echo '{{ hostvars['ceph-1']['bootstrap_keyring'].stdout }}' | base64 -d > /var/lib/ceph/bootstrap-osd/ceph.keyring && ceph-volume raw prepare --bluestore --data /dev/{{ item }}"
loop:
- sda4
- sdb4
- sdc4
- sdd4
- name: Activate OSDs on each host
command: cephadm shell -- ceph cephadm osd activate {{ inventory_hostname }}
- name: Configure CephFS
hosts: ceph_master
tasks:
- name: Create erasure code profile for CephFS data
command: cephadm shell -- ceph osd erasure-code-profile set cephfs_ec k=3 m=1
- name: Create erasure-coded pool for CephFS data
command: cephadm shell -- ceph osd pool create cephfs_data erasure cephfs_ec
- name: Enable EC overwrites on data pool
command: cephadm shell -- ceph osd pool set cephfs_data allow_ec_overwrites true
- name: Create replicated pool for CephFS metadata
command: cephadm shell -- ceph osd pool create cephfs_metadata 32 32 replicated
- name: Enable CephFS on metadata pool
command: cephadm shell -- ceph osd pool application enable cephfs_metadata cephfs
- name: Enable CephFS on data pool
command: cephadm shell -- ceph osd pool application enable cephfs_data cephfs
- name: Create CephFS filesystem
command: cephadm shell -- ceph fs new cephfs cephfs_metadata cephfs_data --force
- name: Deploy MDS daemons
command: cephadm shell -- ceph orch apply mds cephfs --placement="4"
- name: Wait for MDS to become active
shell: |
for i in {1..30}; do
if cephadm shell -- ceph fs status cephfs | grep -q "active"; then
exit 0
fi
sleep 2
done
exit 1
- name: Install ceph-common for kernel client
apt:
name: ceph-common
state: present
update_cache: yes
- name: Create CephFS mount point
file:
path: /mnt/cephfs
state: directory
mode: '0755'
- name: Get admin keyring secret
shell: cephadm shell -- ceph auth get-key client.admin
register: admin_key
- name: Mount CephFS on master
mount:
path: /mnt/cephfs
src: "ceph-1:6789:/"
fstype: ceph
opts: "name=admin,secret={{ admin_key.stdout }}"
state: mounted
- name: Display mount information
debug:
msg: "CephFS is mounted at /mnt/cephfs on {{ inventory_hostname }}. You can now rsync data to root@{{ ansible_host }}:/mnt/cephfs/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment