From ed36a11eabbdbb040652991300cdfc93d51ed491 Mon Sep 17 00:00:00 2001 From: Dimitri Savineau Date: Thu, 31 Oct 2019 16:17:33 -0400 Subject: [PATCH] move crush rule creation from mon to osd role If we want to create crush rules with the create-replicated sub command and device class then we need to have the OSD created before the crush rules otherwise the device classes won't exist. Signed-off-by: Dimitri Savineau --- roles/ceph-mon/tasks/main.yml | 4 --- .../tasks/crush_rules.yml | 35 ++++++++++--------- roles/ceph-osd/tasks/main.yml | 4 +++ 3 files changed, 22 insertions(+), 21 deletions(-) rename roles/{ceph-mon => ceph-osd}/tasks/crush_rules.yml (61%) diff --git a/roles/ceph-mon/tasks/main.yml b/roles/ceph-mon/tasks/main.yml index 7164ac89d..528c7ce8c 100644 --- a/roles/ceph-mon/tasks/main.yml +++ b/roles/ceph-mon/tasks/main.yml @@ -23,7 +23,3 @@ when: - secure_cluster | bool - inventory_hostname == groups[mon_group_name] | first - -- name: crush_rules.yml - include_tasks: crush_rules.yml - when: crush_rule_config | bool diff --git a/roles/ceph-mon/tasks/crush_rules.yml b/roles/ceph-osd/tasks/crush_rules.yml similarity index 61% rename from roles/ceph-mon/tasks/crush_rules.yml rename to roles/ceph-osd/tasks/crush_rules.yml index f77a513ff..02e5bef51 100644 --- a/roles/ceph-mon/tasks/crush_rules.yml +++ b/roles/ceph-osd/tasks/crush_rules.yml @@ -2,29 +2,29 @@ - name: configure crush hierarchy ceph_crush: cluster: "{{ cluster }}" - location: "{{ hostvars[item]['osd_crush_location'] }}" - containerized: "{{ container_exec_cmd }}" - with_items: "{{ groups[osd_group_name] }}" + location: "{{ osd_crush_location }}" + containerized: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }}" register: config_crush_hierarchy + delegate_to: '{{ groups[mon_group_name][0] }}' when: - - inventory_hostname == groups.get(mon_group_name) | last - - create_crush_tree | bool - - hostvars[item]['osd_crush_location'] is defined + - hostvars[groups[mon_group_name][0]]['create_crush_tree'] | default(false) | bool + - 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 }}" + command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} osd crush rule create-simple {{ item.name }} {{ item.root }} {{ item.type }}" changed_when: false - when: inventory_hostname == groups.get(mon_group_name) | last + with_items: "{{ hostvars[groups[mon_group_name][0]]['crush_rules'] | unique }}" + delegate_to: '{{ groups[mon_group_name][0] }}' + run_once: true - name: get id for new default crush rule - command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} osd -f json crush rule dump {{ item.name }}" + command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} 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 + with_items: "{{ hostvars[groups[mon_group_name][0]]['crush_rules'] | unique }}" + delegate_to: '{{ groups[mon_group_name][0] }}' + run_once: true + when: item.default | bool # 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. @@ -33,15 +33,15 @@ 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) + run_once: true + when: not item.get('skipped', false) - name: insert new default crush rule into daemon to prevent restart command: "{{ hostvars[item]['container_exec_cmd'] | default('') }} ceph --admin-daemon /var/run/ceph/{{ cluster }}-mon.{{ hostvars[item]['monitor_name'] }}.asok 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] }}" + run_once: true when: - not config_crush_hierarchy.get('skipped', false) - info_ceph_default_crush_rule_yaml | default('') | length > 0 @@ -54,6 +54,7 @@ value: "{{ info_ceph_default_crush_rule_yaml.rule_id }}" delegate_to: "{{ item }}" with_items: "{{ groups[mon_group_name] }}" + run_once: true when: - not config_crush_hierarchy.get('skipped', false) - info_ceph_default_crush_rule_yaml | default('') | length > 0 diff --git a/roles/ceph-osd/tasks/main.yml b/roles/ceph-osd/tasks/main.yml index 3993b327d..84df01483 100644 --- a/roles/ceph-osd/tasks/main.yml +++ b/roles/ceph-osd/tasks/main.yml @@ -51,6 +51,10 @@ - name: include_tasks start_osds.yml include_tasks: start_osds.yml +- name: include crush_rules.yml + include_tasks: crush_rules.yml + when: hostvars[groups[mon_group_name][0]]['crush_rule_config'] | default(false) | bool + - name: set_fact openstack_keys_tmp - preserve backward compatibility after the introduction of the ceph_keys module set_fact: openstack_keys_tmp: "{{ openstack_keys_tmp|default([]) + [ { 'key': item.key, 'name': item.name, 'caps': { 'mon': item.mon_cap, 'osd': item.osd_cap|default(''), 'mds': item.mds_cap|default(''), 'mgr': item.mgr_cap|default('') } , 'mode': item.mode } ] }}"