refactor(vars): add system/hypervisor dict inputs
This commit is contained in:
85
roles/partitioning/tasks/extra_disks.yml
Normal file
85
roles/partitioning/tasks/extra_disks.yml
Normal file
@@ -0,0 +1,85 @@
|
||||
---
|
||||
- name: Determine additional disks to auto-mount
|
||||
ansible.builtin.set_fact:
|
||||
partitioning_extra_disks: >-
|
||||
{{
|
||||
(system_cfg.disks | default([]))[1:]
|
||||
| selectattr('mount')
|
||||
| list
|
||||
}}
|
||||
changed_when: false
|
||||
|
||||
- name: Validate additional disks do not target install_drive
|
||||
when: partitioning_extra_disks | length > 0
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.device is defined
|
||||
- item.device | string | length > 0
|
||||
- item.device != install_drive
|
||||
- item.partition is defined
|
||||
- item.partition | string | length > 0
|
||||
- item.fstype is defined
|
||||
- item.fstype in ['btrfs', 'ext4', 'xfs']
|
||||
- item.mount is defined
|
||||
- item.mount | string | length > 0
|
||||
- item.mount.startswith('/')
|
||||
- item.mount != '/'
|
||||
fail_msg: "Invalid additional disk definition: {{ item | to_json }}"
|
||||
quiet: true
|
||||
loop: "{{ partitioning_extra_disks }}"
|
||||
loop_control:
|
||||
label: "{{ item | to_json }}"
|
||||
|
||||
- name: Partition additional disks
|
||||
when: partitioning_extra_disks | length > 0
|
||||
community.general.parted:
|
||||
device: "{{ item.device }}"
|
||||
label: gpt
|
||||
number: 1
|
||||
part_start: "1MiB"
|
||||
part_end: "100%"
|
||||
name: "{{ (item.label | default('') | string | length > 0) | ternary(item.label, 'data') }}"
|
||||
state: present
|
||||
loop: "{{ partitioning_extra_disks }}"
|
||||
loop_control:
|
||||
label: "{{ item.device }}"
|
||||
|
||||
- name: Settle partition tables for additional disks
|
||||
when: partitioning_extra_disks | length > 0
|
||||
ansible.builtin.command: udevadm settle
|
||||
changed_when: false
|
||||
|
||||
- name: Create filesystems on additional disks
|
||||
when: partitioning_extra_disks | length > 0
|
||||
community.general.filesystem:
|
||||
dev: "{{ item.partition }}"
|
||||
fstype: "{{ item.fstype }}"
|
||||
opts: "{{ ('-L ' ~ item.label) if (item.label | default('') | string | length) > 0 else omit }}"
|
||||
force: true
|
||||
loop: "{{ partitioning_extra_disks }}"
|
||||
loop_control:
|
||||
label: "{{ item.partition }}"
|
||||
|
||||
- name: Ensure mount directories exist for additional disks
|
||||
when: partitioning_extra_disks | length > 0
|
||||
ansible.builtin.file:
|
||||
path: "/mnt{{ item.mount }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
loop: "{{ partitioning_extra_disks }}"
|
||||
loop_control:
|
||||
label: "{{ item.mount }}"
|
||||
|
||||
- name: Mount additional disks for fstab generation
|
||||
when: partitioning_extra_disks | length > 0
|
||||
ansible.posix.mount:
|
||||
path: "/mnt{{ item.mount }}"
|
||||
src: "{{ item.partition }}"
|
||||
fstype: "{{ item.fstype }}"
|
||||
opts: "{{ item.opts | default('defaults') }}"
|
||||
state: mounted
|
||||
loop: "{{ partitioning_extra_disks }}"
|
||||
loop_control:
|
||||
label: "{{ item.mount }}"
|
||||
Reference in New Issue
Block a user