ceph-facts: Fix osd_pool_default_crush_rule fact

The `osd_pool_default_crush_rule` is set based on `crush_rule_variable`, which
is the output of a `grep` command.

However, two consecutive tasks can set that variable, and if the second task is
skipped, it still overwrites the `crush_rule_variable`, leading the
`osd_pool_default_crush_rule` to be set to `ceph_osd_pool_default_crush_rule`
instead of the output of the first task.

This commit ensures that the fact is set right after the `crush_rule_variable`
is assigned, before it can be overwritten.

Closes #5912

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
(cherry picked from commit c5f7343a2f)
pull/6035/head
Benoît Knecht 2020-10-07 09:44:29 +02:00 committed by Dimitri Savineau
parent bb3cfd0481
commit deaf60316a
1 changed files with 23 additions and 17 deletions

View File

@ -298,30 +298,36 @@
path: '/etc/ceph/{{ cluster }}.conf' path: '/etc/ceph/{{ cluster }}.conf'
register: ceph_conf register: ceph_conf
- name: set default osd_pool_default_crush_rule fact
set_fact:
osd_pool_default_crush_rule: "{{ ceph_osd_pool_default_crush_rule }}"
- name: get default crush rule value from ceph configuration - name: get default crush rule value from ceph configuration
command: grep 'osd pool default crush rule' /etc/ceph/{{ cluster }}.conf block:
register: crush_rule_variable - &read-osd-pool-default-crush-rule
changed_when: false name: read osd pool default crush rule
check_mode: no command: grep 'osd pool default crush rule' /etc/ceph/{{ cluster }}.conf
failed_when: false register: crush_rule_variable
changed_when: false
check_mode: no
failed_when: crush_rule_variable.rc not in (0, 1)
- &set-osd-pool-default-crush-rule-fact
name: set osd_pool_default_crush_rule fact
set_fact:
osd_pool_default_crush_rule: "{{ crush_rule_variable.stdout.split(' = ')[1] }}"
when: crush_rule_variable.rc == 0
when: ceph_conf.stat.exists | bool when: ceph_conf.stat.exists | bool
- name: get default crush rule value from running monitor ceph configuration - name: get default crush rule value from running monitor ceph configuration
command: grep 'osd pool default crush rule' /etc/ceph/{{ cluster }}.conf block:
register: crush_rule_variable - <<: *read-osd-pool-default-crush-rule
changed_when: false run_once: true
check_mode: no delegate_to: "{{ running_mon }}"
failed_when: false - *set-osd-pool-default-crush-rule-fact
run_once: true
delegate_to: "{{ running_mon }}"
when: when:
- running_mon is defined - running_mon is defined
- not ceph_conf.stat.exists | bool - not ceph_conf.stat.exists | bool
- name: set_fact osd_pool_default_crush_rule
set_fact:
osd_pool_default_crush_rule: "{{ crush_rule_variable.stdout.split(' = ')[1] if crush_rule_variable.get('rc', 1) | int == 0 else ceph_osd_pool_default_crush_rule }}"
- name: import_tasks set_monitor_address.yml - name: import_tasks set_monitor_address.yml
import_tasks: set_monitor_address.yml import_tasks: set_monitor_address.yml
when: groups.get(mon_group_name, []) | length > 0 when: groups.get(mon_group_name, []) | length > 0
@ -355,4 +361,4 @@
with_items: with_items:
- "{{ groups[mon_group_name] if groups[mon_group_name] | default([]) | length > 0 else [] }}" - "{{ groups[mon_group_name] if groups[mon_group_name] | default([]) | length > 0 else [] }}"
- "{{ groups[mds_group_name] if groups[mds_group_name] | default([]) | length > 0 else [] }}" - "{{ groups[mds_group_name] if groups[mds_group_name] | default([]) | length > 0 else [] }}"
- "{{ groups[client_group_name] if groups[client_group_name] | default([]) | length > 0 else [] }}" - "{{ groups[client_group_name] if groups[client_group_name] | default([]) | length > 0 else [] }}"