62 lines
2.6 KiB
YAML
62 lines
2.6 KiB
YAML
---
|
|
# The virtualization role attaches system.disks to SCSI controller 0 in list order, and
|
|
# vSphere never gives a disk unit 7 (the controller's own address). The kernel's sdX order
|
|
# is not that order and differs between the install environment and the installed OS, so
|
|
# a disk derived as /dev/sd<letter of its index> can be the wrong one. Resolve by target.
|
|
- name: List disks with their SCSI address
|
|
ansible.builtin.command: lsblk -dnpo NAME,TYPE,HCTL
|
|
register: partitioning_vmware_lsblk
|
|
changed_when: false
|
|
|
|
- name: Map SCSI targets to devices
|
|
vars:
|
|
_scsi: >-
|
|
{%- set out = [] -%}
|
|
{%- for line in partitioning_vmware_lsblk.stdout_lines -%}
|
|
{%- set p = line.split() -%}
|
|
{%- if (p | length) == 3 and p[1] == 'disk' and p[2] is match('^\d+:0:\d+:0$') -%}
|
|
{%- set _ = out.append({'name': p[0], 'host': p[2].split(':')[0], 'target': p[2].split(':')[2]}) -%}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{{ out }}
|
|
ansible.builtin.set_fact:
|
|
partitioning_vmware_hosts: "{{ _scsi | map(attribute='host') | unique | list }}"
|
|
partitioning_vmware_targets: "{{ _scsi | items2dict(key_name='target', value_name='name') }}"
|
|
partitioning_vmware_target_count: "{{ _scsi | length }}"
|
|
|
|
- name: Assert the system disks sit on one SCSI controller with unique targets
|
|
ansible.builtin.assert:
|
|
that:
|
|
- partitioning_vmware_hosts | length == 1
|
|
- partitioning_vmware_targets | length == partitioning_vmware_target_count | int
|
|
fail_msg: >-
|
|
Expected every disk on one SCSI controller with unique targets, got
|
|
{{ partitioning_vmware_lsblk.stdout_lines | select('search', ' disk ') | list }}.
|
|
quiet: true
|
|
|
|
- name: Assert each system disk has a device at its SCSI target
|
|
vars:
|
|
_target: "{{ (idx if idx < 7 else idx + 1) | string }}"
|
|
ansible.builtin.assert:
|
|
that:
|
|
- _target in partitioning_vmware_targets
|
|
fail_msg: "system.disks[{{ idx }}] ({{ item.size }} GB) expects a disk at SCSI target {{ _target }}, none found."
|
|
quiet: true
|
|
loop: "{{ system_cfg.disks }}"
|
|
loop_control:
|
|
index_var: idx
|
|
label: "{{ idx }}"
|
|
|
|
- name: Point system disks and install_drive at the resolved devices
|
|
vars:
|
|
_disks: >-
|
|
{%- set out = [] -%}
|
|
{%- for d in system_cfg.disks -%}
|
|
{%- set dev = partitioning_vmware_targets[(loop.index0 if loop.index0 < 7 else loop.index0 + 1) | string] -%}
|
|
{%- set _ = out.append(d | combine({'device': dev, 'partition': dev ~ '1'})) -%}
|
|
{%- endfor -%}
|
|
{{ out }}
|
|
ansible.builtin.set_fact:
|
|
system_cfg: "{{ system_cfg | combine({'disks': _disks}) }}"
|
|
install_drive: "{{ _disks[0].device }}"
|