ceph-ansible/roles/ceph-mon/tasks/crush_rules.yml

60 lines
2.5 KiB
YAML
Raw Normal View History

---
- name: configure crush hierarchy
ceph_crush:
cluster: "{{ cluster }}"
location: "{{ hostvars[item]['osd_crush_location'] }}"
containerized: "{{ container_exec_cmd }}"
with_items: "{{ groups[osd_group_name] }}"
register: config_crush_hierarchy
when:
- inventory_hostname == groups.get(mon_group_name) | last
- create_crush_tree | bool
- hostvars[item]['osd_crush_location'] is defined
- name: create configured crush rules
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} osd crush rule create-simple {{ item.name }} {{ item.root }} {{ item.type }}"
with_items: "{{ crush_rules | unique }}"
changed_when: false
when: inventory_hostname == groups.get(mon_group_name) | last
- name: get id for new default crush rule
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} osd -f json crush rule dump {{ item.name }}"
register: info_ceph_default_crush_rule
changed_when: false
with_items: "{{ crush_rules }}"
when:
- inventory_hostname == groups.get(mon_group_name) | last
- item.default
# If multiple rules are set as default (should not be) then the last one is taken as actual default.
# the with_items statement overrides each iteration with the new one.
# NOTE(leseb): we should actually fail if multiple rules are set as default
- name: set_fact info_ceph_default_crush_rule_yaml
set_fact:
info_ceph_default_crush_rule_yaml: "{{ item.stdout | from_json() }}"
with_items: "{{ info_ceph_default_crush_rule.results }}"
when:
- inventory_hostname == groups.get(mon_group_name) | last
- not item.get('skipped', false)
- name: insert new default crush rule into daemon to prevent restart
command: "{{ hostvars[item]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} daemon mon.{{ hostvars[item]['monitor_name'] }} config set osd_pool_default_crush_rule {{ info_ceph_default_crush_rule_yaml.rule_id }}"
changed_when: false
delegate_to: "{{ item }}"
with_items: "{{ groups[mon_group_name] }}"
when:
- not config_crush_hierarchy.get('skipped', false)
- info_ceph_default_crush_rule_yaml | default('') | length > 0
- name: "add new default crush rule to {{ cluster }}.conf"
ini_file:
dest: "/etc/ceph/{{ cluster }}.conf"
section: "global"
option: "osd pool default crush rule"
value: "{{ info_ceph_default_crush_rule_yaml.rule_id }}"
delegate_to: "{{ item }}"
with_items: "{{ groups[mon_group_name] }}"
when:
- not config_crush_hierarchy.get('skipped', false)
- info_ceph_default_crush_rule_yaml | default('') | length > 0