--- - name: Determine additional disks to auto-mount ansible.builtin.set_fact: partitioning_extra_disks: >- {{ (system_cfg.disks | default([]))[1:] | selectattr('mount.path') | 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.mount.fstype is defined - item.mount.fstype in ['btrfs', 'ext4', 'xfs'] - item.mount.path is defined - item.mount.path | string | length > 0 - item.mount.path.startswith('/') - item.mount.path != '/' 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.mount.label | default('') | string | length > 0) | ternary(item.mount.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.mount.fstype }}" opts: "{{ ('-L ' ~ item.mount.label) if (item.mount.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.path }}" state: directory owner: root group: root mode: "0755" loop: "{{ partitioning_extra_disks }}" loop_control: label: "{{ item.mount.path }}" - name: Mount additional disks for fstab generation when: partitioning_extra_disks | length > 0 ansible.posix.mount: path: "/mnt{{ item.mount.path }}" src: "{{ item.partition }}" fstype: "{{ item.mount.fstype }}" opts: "{{ item.mount.opts | default('defaults') }}" state: mounted loop: "{{ partitioning_extra_disks }}" loop_control: label: "{{ item.mount.path }}"