fix raid
This commit is contained in:
@@ -87,56 +87,75 @@
|
|||||||
mdstat_text: "{{ mdstat_cmd.stdout | default('') }}"
|
mdstat_text: "{{ mdstat_cmd.stdout | default('') }}"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Extract selected md block from mdstat # English comments
|
- name: Extract selected md block from mdstat (no regex) # English comments
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
raid_block: >-
|
raid_block: >-
|
||||||
{{
|
{%- set ns = namespace(block='') -%}
|
||||||
(
|
{%- for b in (mdstat_text.split('\n\n')) -%}
|
||||||
mdstat_text
|
{%- set bb = (b | trim) -%}
|
||||||
| regex_findall(
|
{%- if bb.startswith(raid_md ~ ' :') or bb.startswith(raid_md ~ ':') -%}
|
||||||
'(?ms)^' ~ raid_md ~ '\\s*:.*?(?=^md\\d+\\s*:|^unused devices:|\\Z)'
|
{%- set ns.block = bb -%}
|
||||||
)
|
{%- endif -%}
|
||||||
| first
|
{%- endfor -%}
|
||||||
| default('', true)
|
{{ ns.block }}
|
||||||
)
|
|
||||||
}}
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Parse RAID status from mdstat (safe parsing) # English comments
|
- name: Parse RAID status from mdstat (no regex) # English comments
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
raid_present: "{{ (raid_block | length) > 0 }}"
|
raid_present: "{{ (raid_block | trim | length) > 0 }}"
|
||||||
|
|
||||||
|
# Extract [UU] / [U_] token by scanning bracket tokens and keeping only U/_ chars
|
||||||
raid_status: >-
|
raid_status: >-
|
||||||
{{
|
{%- set ns = namespace(st='') -%}
|
||||||
(
|
{%- for line in (raid_block.splitlines() if (raid_block | length) > 0 else []) -%}
|
||||||
raid_block
|
{%- for tok in line.split() -%}
|
||||||
| regex_findall('\\[[0-9]+/[0-9]+\\]\\s*\\[([U_]+)\\]')
|
{%- if tok.startswith('[') and tok.endswith(']') -%}
|
||||||
| first
|
{%- set inner = tok[1:-1] -%}
|
||||||
| default('', true)
|
{%- if (inner | length) > 0 and ((inner | list | difference(['U','_'])) | length == 0) -%}
|
||||||
)
|
{%- set ns.st = inner -%}
|
||||||
}}
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{{ ns.st }}
|
||||||
|
|
||||||
raid_is_degraded: "{{ (raid_status | length > 0) and ('_' in raid_status) }}"
|
raid_is_degraded: "{{ (raid_status | length > 0) and ('_' in raid_status) }}"
|
||||||
raid_is_rebuilding: "{{ raid_block is search('(?i)\\b(resync|recovery|reshape|repair)\\b') }}"
|
|
||||||
raid_is_checking: "{{ raid_block is search('(?i)\\bcheck\\b') }}"
|
raid_block_lower: "{{ raid_block | lower }}"
|
||||||
|
raid_is_rebuilding: >-
|
||||||
|
{{
|
||||||
|
('resync' in raid_block_lower) or
|
||||||
|
('recovery' in raid_block_lower) or
|
||||||
|
('reshape' in raid_block_lower) or
|
||||||
|
('repair' in raid_block_lower)
|
||||||
|
}}
|
||||||
|
raid_is_checking: "{{ 'check' in raid_block_lower }}"
|
||||||
|
|
||||||
|
# First line that contains an action keyword
|
||||||
raid_action_line: >-
|
raid_action_line: >-
|
||||||
{{
|
{%- set ns = namespace(line='') -%}
|
||||||
(
|
{%- set keys = ['resync','recovery','reshape','repair','check'] -%}
|
||||||
raid_block
|
{%- for line in (raid_block.splitlines() if (raid_block | length) > 0 else []) -%}
|
||||||
| regex_findall('(?im)^(\\s*\\[[^\\]]+\\].*\\b(?:resync|recovery|reshape|repair|check)\\b.*)$')
|
{%- set l = (line | lower) -%}
|
||||||
| first
|
{%- for k in keys -%}
|
||||||
| default('', true)
|
{%- if ns.line == '' and (k in l) -%}
|
||||||
)
|
{%- set ns.line = (line | trim) -%}
|
||||||
}}
|
{%- endif -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{{ ns.line }}
|
||||||
|
|
||||||
|
# Parse progress from ".... = 12.3%" if present
|
||||||
raid_progress: >-
|
raid_progress: >-
|
||||||
{{
|
{%- set ns = namespace(p='') -%}
|
||||||
(
|
{%- if (raid_action_line | length) > 0 and ('=' in raid_action_line) and ('%' in raid_action_line) -%}
|
||||||
raid_block
|
{%- set right = raid_action_line.split('=', 1)[1] -%}
|
||||||
| regex_findall('(?i)\\b(?:resync|recovery|reshape|repair|check)\\b\\s*=\\s*([0-9.]+)%')
|
{%- set ns.p = (right.split('%', 1)[0] | trim) -%}
|
||||||
| first
|
{%- endif -%}
|
||||||
| default('', true)
|
{{ ns.p }}
|
||||||
)
|
|
||||||
}}
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
|
|
||||||
- name: Debug | Show mdstat and parsed values # English comments
|
- name: Debug | Show mdstat and parsed values # English comments
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: |
|
msg: |
|
||||||
|
|||||||
Reference in New Issue
Block a user