72 lines
2.2 KiB
YAML
72 lines
2.2 KiB
YAML
---
|
|
- name: Root ZFS Pool | Check for existing zroot zfs volume
|
|
ansible.builtin.command: zpool list -Ho name zroot
|
|
register: zroot_check
|
|
changed_when: false
|
|
ignore_errors: true
|
|
|
|
- name: Root ZFS Pool |
|
|
when: zroot_check.rc != 0
|
|
block:
|
|
- name: Root ZFS Pool | initialize disk device to id table
|
|
ansible.builtin.set_fact:
|
|
partition_device_to_ids: {}
|
|
|
|
- name: Root ZFS Pool | create disk device -> id table
|
|
ansible.builtin.set_fact:
|
|
partition_device_to_ids: >-
|
|
{{
|
|
partition_device_to_ids
|
|
| combine({ item.value: (partition_device_to_ids[item.value] | default([])) + [item.key] })
|
|
}}
|
|
with_items: "{{ base_partitions_by_id | dict2items }}"
|
|
|
|
- name: Root ZFS Pool | create zroot volume
|
|
become: true
|
|
ansible.builtin.command: >-
|
|
zpool create -f -o ashift=12
|
|
-o autotrim=on
|
|
-O devices=off
|
|
-O relatime=on
|
|
-O xattr=sa
|
|
-O acltype=posixacl
|
|
-O normalization=formD
|
|
-O compression=lz4
|
|
-O canmount=off
|
|
-O mountpoint=none
|
|
-R /mnt
|
|
zroot {{ mirror }} {{ base_root_partitions | map('extract', partition_device_to_ids) | map('first') | list | join(' ') }}
|
|
vars:
|
|
mirror: "{{ 'mirror' if base_root_partitions | length > 1 else '' }}"
|
|
changed_when: true
|
|
|
|
- name: Root ZFS Pool | create zroot/ROOT and zroot/DATA volumes
|
|
community.general.zfs:
|
|
name: "zroot/{{ item }}"
|
|
state: present
|
|
register: zfs_zroot_root_volume
|
|
with_items: [ROOT, DATA]
|
|
|
|
- name: Root ZFS Pool | create zroot/ROOT/arch
|
|
community.general.zfs:
|
|
name: zroot/ROOT/arch
|
|
state: present
|
|
extra_zfs_properties:
|
|
canmount: noauto
|
|
mountpoint: /
|
|
when: zfs_zroot_root_volume.changed
|
|
|
|
- name: Root ZFS Pool | create zroot/DATA/home
|
|
community.general.zfs:
|
|
name: zroot/DATA/home
|
|
state: present
|
|
extra_zfs_properties:
|
|
mountpoint: /home
|
|
|
|
- name: Root ZFS Pool | Export zroot pool
|
|
ansible.builtin.command: zpool export zroot
|
|
changed_when: false
|
|
|
|
- name: Root ZFS Pool | Import zroot pool (-R /mnt)
|
|
ansible.builtin.command: zpool import -R /mnt zroot -N
|
|
changed_when: false
|