|
13 | 13 | mdadm_force_wipe is defined and
|
14 | 14 | mdadm_force_wipe
|
15 | 15 |
|
| 16 | +- name: main | Validate auto_detect configuration |
| 17 | + fail: |
| 18 | + msg: "Error: auto_detect is set to true but devices are also defined for array {{ item.name }}. Use either devices OR auto_detect, not both." |
| 19 | + with_items: "{{ mdadm_arrays }}" |
| 20 | + when: > |
| 21 | + item.auto_detect | default(false) and |
| 22 | + item.devices is defined and |
| 23 | + item.devices | length > 0 |
| 24 | +
|
16 | 25 | - include_tasks: detect_unused_disks.yml
|
| 26 | + when: mdadm_arrays | selectattr('auto_detect', 'defined') | selectattr('auto_detect', 'equalto', true) | list | length > 0 |
| 27 | + |
| 28 | +- name: main | Validate sufficient disks for auto-detection |
| 29 | + fail: |
| 30 | + msg: "Error: Not enough unused disks found for auto-detection. Found {{ unused_disks | length }} disks, but {{ item.name }} requires at least {{ item.min_disks | default(3) }} disks." |
| 31 | + with_items: "{{ mdadm_arrays }}" |
17 | 32 | when: >
|
18 |
| - mdadm_auto_detect_arrays and |
19 |
| - (mdadm_arrays | length == 0) |
| 33 | + item.auto_detect | default(false) and |
| 34 | + (item.devices is not defined or item.devices | length == 0) and |
| 35 | + unused_disks is defined and |
| 36 | + unused_disks | length < item.min_disks | default(3) |
20 | 37 |
|
21 |
| -- name: main | Set auto-detected arrays |
| 38 | +- name: main | Set auto-detected devices for arrays with auto_detect |
22 | 39 | set_fact:
|
23 |
| - mdadm_arrays: "{{ mdadm_auto_detect_config | map('combine', {'devices': unused_disks}) | list }}" |
| 40 | + mdadm_arrays: "{{ mdadm_arrays_updated }}" |
| 41 | + vars: |
| 42 | + mdadm_arrays_updated: >- |
| 43 | + {%- set result = [] -%} |
| 44 | + {%- for array in mdadm_arrays -%} |
| 45 | + {%- if array.auto_detect | default(false) and (array.devices is not defined or array.devices | length == 0) -%} |
| 46 | + {%- if unused_disks | length >= array.min_disks | default(3) -%} |
| 47 | + {%- set updated_array = array | combine({'devices': unused_disks}) -%} |
| 48 | + {%- set _ = result.append(updated_array) -%} |
| 49 | + {%- else -%} |
| 50 | + {%- set _ = result.append(array) -%} |
| 51 | + {%- endif -%} |
| 52 | + {%- else -%} |
| 53 | + {%- set _ = result.append(array) -%} |
| 54 | + {%- endif -%} |
| 55 | + {%- endfor -%} |
| 56 | + {{ result }} |
24 | 57 | when: >
|
25 |
| - mdadm_auto_detect_arrays and |
26 |
| - (mdadm_arrays | length == 0) and |
27 |
| - (unused_disks | length >= mdadm_auto_detect_config[0].min_disks) |
| 58 | + unused_disks is defined and |
| 59 | + mdadm_arrays | selectattr('auto_detect', 'defined') | selectattr('auto_detect', 'equalto', true) | list | length > 0 |
28 | 60 |
|
29 | 61 | - include_tasks: arrays.yml
|
0 commit comments