ceph-ansible/roles/ceph-handler/tasks/handler_osds.yml

93 lines
3.4 KiB
YAML

---
- name: set_fact trigger_restart
set_fact:
trigger_restart: true
loop: "{{ groups[osd_group_name] }}"
when: hostvars[item]['handler_osd_status'] | default(False) | bool
run_once: true
- name: osd handler
when: trigger_restart | default(False) | bool
block:
- name: get pool list
command: "{{ ceph_cmd }} --cluster {{ cluster }} osd pool ls detail -f json"
register: pool_list
delegate_to: "{{ groups.get(mon_group_name, [])[0] }}"
run_once: true
changed_when: false
check_mode: false
- name: get balancer module status
command: "{{ ceph_cmd }} --cluster {{ cluster }} balancer status -f json"
register: balancer_status
run_once: true
delegate_to: "{{ groups[mon_group_name][0] }}"
changed_when: false
check_mode: false
- name: set_fact pools_pgautoscaler_mode
set_fact:
pools_pgautoscaler_mode: "{{ pools_pgautoscaler_mode | default([]) | union([{'name': item.pool_name, 'mode': item.pg_autoscale_mode}]) }}"
run_once: true
with_items: "{{ pool_list.stdout | default('{}') | from_json }}"
- name: disable balancer
command: "{{ ceph_cmd }} --cluster {{ cluster }} balancer off"
run_once: true
delegate_to: "{{ groups[mon_group_name][0] }}"
changed_when: false
when: (balancer_status.stdout | from_json)['active'] | bool
- name: disable pg autoscale on pools
command: "{{ ceph_cmd }} --cluster {{ cluster }} osd pool set {{ item.name }} pg_autoscale_mode off"
with_items: "{{ pools_pgautoscaler_mode }}"
delegate_to: "{{ groups.get(mon_group_name, [])[0] }}"
run_once: true
when:
- pools_pgautoscaler_mode is defined
- item.mode == 'on'
# This does not just restart OSDs but everything else too. Unfortunately
# at this time the ansible role does not have an OSD id list to use
# for restarting them specifically.
# This does not need to run during a rolling update as the playbook will
# restart all OSDs using the tasks "start ceph osd" or
# "restart containerized ceph osd"
- name: copy osd restart script
template:
src: restart_osd_daemon.sh.j2
dest: /tmp/restart_osd_daemon.sh
owner: root
group: root
mode: 0750
- name: restart ceph osds daemon(s)
command: /usr/bin/env bash /tmp/restart_osd_daemon.sh
when:
- hostvars[item]['handler_osd_status'] | default(False) | bool
- handler_health_osd_check | bool
- hostvars[item]['_osd_handler_called'] | default(False) | bool
with_items: "{{ groups[osd_group_name] | intersect(ansible_play_batch) }}"
delegate_to: "{{ item }}"
run_once: True
- name: set _osd_handler_called after restart
set_fact:
_osd_handler_called: False
- name: re-enable pg autoscale on pools
command: "{{ ceph_cmd }} --cluster {{ cluster }} osd pool set {{ item.name }} pg_autoscale_mode on"
with_items: "{{ pools_pgautoscaler_mode }}"
delegate_to: "{{ groups.get(mon_group_name, [])[0] }}"
run_once: true
when:
- pools_pgautoscaler_mode is defined
- item.mode == 'on'
- name: re-enable balancer
command: "{{ ceph_cmd }} --cluster {{ cluster }} balancer on"
run_once: true
delegate_to: "{{ groups[mon_group_name][0] }}"
changed_when: false
when: (balancer_status.stdout | from_json)['active'] | bool