Skip to content

Instantly share code, notes, and snippets.

@lae
Last active November 7, 2016 22:01
Show Gist options
  • Save lae/91d9e8ced7e627b460dff0b139b2c703 to your computer and use it in GitHub Desktop.
Save lae/91d9e8ced7e627b460dff0b139b2c703 to your computer and use it in GitHub Desktop.
# Collect all down/incomplete PGs and create "inventory" files for playbook_remove_pg.yml per PG (separated by empty lines)
ceph health detail |
grep -P "is (down\+)?incomplete, acting" |
cut -d' ' -f2 |
while read pg
do
ceph pg $pg query |
jq -r '.recovery_state[0].probing_osds[]' |
while read osd
do
host=$(ceph osd find $osd | jq -r '.crush_location.host')
echo $host $osd
done |
sort |
awk '{h=$1;if(a[h])a[h]=a[h] OFS $2;else{a[h]=$0;b[++i]=h}}END{for(x=1;x<=i;x++)print a[b[x]]}' |
while read host osds
do
echo "$host osds=[$(echo $osds | tr ' ' ,)] pg=$pg"
done
echo
done
---
- hosts: all
become: True
tasks:
- name: Check that PG exists
stat:
path: "/var/lib/ceph/osd/ceph-{{ item }}/current/{{ pg }}_head"
register: pgstat
with_items: "{{ osds }}"
- debug: var=item
with_items: "{{ pgstat.results }}"
- name: Stop OSD
service:
name: "ceph-osd@{{ item.item }}"
state: stopped
with_items: "{{ pgstat.results }}"
when: item.stat.exists
- name: Move PG away
shell: "mv /var/lib/ceph/osd/ceph-{{ item.item }}/current/{{ pg }}_head /root/backup_{{ item.item }}_{{ pg }}; sleep 10"
args:
creates: "/root/backup_{{ item.item }}_{{ pg }}"
with_items: "{{ pgstat.results }}"
when: item.stat.exists
- name: Restart OSD
service:
name: "ceph-osd@{{ item.item }}"
state: restarted
with_items: "{{ pgstat.results }}"
when: item.stat.exists
- name: Restart OSD (post-op)
service:
name: "ceph-osd@{{ item.item }}"
state: restarted
with_items: "{{ pgstat.results }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment