refactor(schema): move filesystem into system dictionary
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
changed_when: configuration_bootloader_result.rc == 0
|
changed_when: configuration_bootloader_result.rc == 0
|
||||||
|
|
||||||
- name: Ensure lvm2 for non btrfs filesystems
|
- name: Ensure lvm2 for non btrfs filesystems
|
||||||
when: os | lower == "archlinux" and filesystem != "btrfs"
|
when: os | lower == "archlinux" and system_cfg.filesystem != "btrfs"
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /mnt/etc/mkinitcpio.conf
|
path: /mnt/etc/mkinitcpio.conf
|
||||||
regexp: "^(HOOKS=.*block)(?!.*lvm2)(.*)"
|
regexp: "^(HOOKS=.*block)(?!.*lvm2)(.*)"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
- name: Adjust XFS mount options and disable large extent
|
- name: Adjust XFS mount options and disable large extent
|
||||||
when: os in ["almalinux", "rocky", "rhel"] and filesystem == "xfs"
|
when: os in ["almalinux", "rocky", "rhel"] and system_cfg.filesystem == "xfs"
|
||||||
ansible.builtin.replace:
|
ansible.builtin.replace:
|
||||||
path: /mnt/etc/fstab
|
path: /mnt/etc/fstab
|
||||||
regexp: "(xfs.*?)(attr2)"
|
regexp: "(xfs.*?)(attr2)"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
{{
|
{{
|
||||||
(
|
(
|
||||||
partitioning_main_uuid.stdout
|
partitioning_main_uuid.stdout
|
||||||
if (filesystem | lower) == 'btrfs'
|
if (system_cfg.filesystem | lower) == 'btrfs'
|
||||||
else (partitioning_uuid_root | default([]) | first | default(''))
|
else (partitioning_uuid_root | default([]) | first | default(''))
|
||||||
)
|
)
|
||||||
| default('')
|
| default('')
|
||||||
@@ -36,11 +36,11 @@
|
|||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (filesystem | lower) != 'btrfs'
|
if (system_cfg.filesystem | lower) != 'btrfs'
|
||||||
else []
|
else []
|
||||||
}}
|
}}
|
||||||
grub_root_flags: >-
|
grub_root_flags: >-
|
||||||
{{ ['rootflags=subvol=@'] if (filesystem | lower) == 'btrfs' else [] }}
|
{{ ['rootflags=subvol=@'] if (system_cfg.filesystem | lower) == 'btrfs' else [] }}
|
||||||
grub_cmdline_linux_base: >-
|
grub_cmdline_linux_base: >-
|
||||||
{{
|
{{
|
||||||
(['crashkernel=auto'] + grub_lvm_args)
|
(['crashkernel=auto'] + grub_lvm_args)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ system_defaults:
|
|||||||
type: "virtual" # virtual|physical
|
type: "virtual" # virtual|physical
|
||||||
os: ""
|
os: ""
|
||||||
version: ""
|
version: ""
|
||||||
|
filesystem: ""
|
||||||
name: ""
|
name: ""
|
||||||
id: ""
|
id: ""
|
||||||
cpus: 0
|
cpus: 0
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
system_raw: "{{ system_defaults | combine(system, recursive=True) }}"
|
system_raw: "{{ system_defaults | combine(system, recursive=True) }}"
|
||||||
system_type: "{{ system_raw.type | string | lower }}"
|
system_type: "{{ system_raw.type | string | lower }}"
|
||||||
system_os_input: "{{ system_raw.os | default('') | string | lower }}"
|
system_os_input: "{{ system_raw.os | default('') | string | lower }}"
|
||||||
|
system_filesystem_input: "{{ system_raw.filesystem | default('') | string | lower }}"
|
||||||
system_name: >-
|
system_name: >-
|
||||||
{{
|
{{
|
||||||
system_raw.name | string | trim
|
system_raw.name | string | trim
|
||||||
@@ -100,6 +101,7 @@
|
|||||||
type: "{{ system_type }}"
|
type: "{{ system_type }}"
|
||||||
os: "{{ system_os_input if system_os_input | length > 0 else ('archlinux' if system_type == 'physical' else '') }}"
|
os: "{{ system_os_input if system_os_input | length > 0 else ('archlinux' if system_type == 'physical' else '') }}"
|
||||||
version: "{{ system_raw.version | default('') | string }}"
|
version: "{{ system_raw.version | default('') | string }}"
|
||||||
|
filesystem: "{{ system_filesystem_input }}"
|
||||||
name: "{{ system_name }}"
|
name: "{{ system_name }}"
|
||||||
id: "{{ system_raw.id | default('') | string }}"
|
id: "{{ system_raw.id | default('') | string }}"
|
||||||
cpus: "{{ [system_raw.cpus | default(0) | int, 0] | max }}"
|
cpus: "{{ [system_raw.cpus | default(0) | int, 0] | max }}"
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
- hypervisor_cfg is mapping
|
- hypervisor_cfg is mapping
|
||||||
- hypervisor_type is defined
|
- hypervisor_type is defined
|
||||||
- hypervisor_type in ["libvirt", "proxmox", "vmware", "xen", "none"]
|
- hypervisor_type in ["libvirt", "proxmox", "vmware", "xen", "none"]
|
||||||
- filesystem is defined
|
- system_cfg.filesystem is defined
|
||||||
- filesystem in ["btrfs", "ext4", "xfs"]
|
- system_cfg.filesystem in ["btrfs", "ext4", "xfs"]
|
||||||
- install_drive is defined
|
- install_drive is defined
|
||||||
- install_drive | string | length > 0
|
- install_drive | string | length > 0
|
||||||
- hostname is defined
|
- hostname is defined
|
||||||
@@ -272,7 +272,7 @@
|
|||||||
- (system_cfg.disks[0].size | float) > 0
|
- (system_cfg.disks[0].size | float) > 0
|
||||||
- (system_cfg.disks[0].size | float) >= 20
|
- (system_cfg.disks[0].size | float) >= 20
|
||||||
- >-
|
- >-
|
||||||
filesystem != "btrfs"
|
system_cfg.filesystem != "btrfs"
|
||||||
or (
|
or (
|
||||||
(system_cfg.disks[0].size | float)
|
(system_cfg.disks[0].size | float)
|
||||||
>= (
|
>= (
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ partitioning_separate_boot: >-
|
|||||||
}}
|
}}
|
||||||
partitioning_boot_fs_fstype: >-
|
partitioning_boot_fs_fstype: >-
|
||||||
{{
|
{{
|
||||||
(filesystem | lower)
|
(system_cfg.filesystem | lower)
|
||||||
if (filesystem | lower) != 'btrfs'
|
if (system_cfg.filesystem | lower) != 'btrfs'
|
||||||
else ('xfs' if is_rhel else 'ext4')
|
else ('xfs' if is_rhel else 'ext4')
|
||||||
}}
|
}}
|
||||||
partitioning_boot_fs_partition_suffix: >-
|
partitioning_boot_fs_partition_suffix: >-
|
||||||
|
|||||||
@@ -246,7 +246,7 @@
|
|||||||
partitioning_luks_uuid: "{{ partitioning_luks_uuid_result.stdout | trim }}"
|
partitioning_luks_uuid: "{{ partitioning_luks_uuid_result.stdout | trim }}"
|
||||||
|
|
||||||
- name: Create LVM logical volumes
|
- name: Create LVM logical volumes
|
||||||
when: filesystem != 'btrfs'
|
when: system_cfg.filesystem != 'btrfs'
|
||||||
block:
|
block:
|
||||||
- name: Create LVM volume group
|
- name: Create LVM volume group
|
||||||
community.general.lvg:
|
community.general.lvg:
|
||||||
@@ -432,14 +432,14 @@
|
|||||||
|
|
||||||
- name: Create swap filesystem
|
- name: Create swap filesystem
|
||||||
when:
|
when:
|
||||||
- filesystem != 'btrfs'
|
- system_cfg.filesystem != 'btrfs'
|
||||||
- system_cfg.features.swap.enabled | bool
|
- system_cfg.features.swap.enabled | bool
|
||||||
community.general.filesystem:
|
community.general.filesystem:
|
||||||
fstype: swap
|
fstype: swap
|
||||||
dev: /dev/sys/swap
|
dev: /dev/sys/swap
|
||||||
|
|
||||||
- name: Create filesystem
|
- name: Create filesystem
|
||||||
ansible.builtin.include_tasks: "{{ filesystem }}.yml"
|
ansible.builtin.include_tasks: "{{ system_cfg.filesystem }}.yml"
|
||||||
|
|
||||||
- name: Get UUID for boot filesystem
|
- name: Get UUID for boot filesystem
|
||||||
ansible.builtin.command: blkid -s UUID -o value '{{ install_drive }}{{ partitioning_boot_partition_suffix }}'
|
ansible.builtin.command: blkid -s UUID -o value '{{ install_drive }}{{ partitioning_boot_partition_suffix }}'
|
||||||
@@ -459,14 +459,14 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Get UUID for LVM root filesystem
|
- name: Get UUID for LVM root filesystem
|
||||||
when: filesystem != 'btrfs'
|
when: system_cfg.filesystem != 'btrfs'
|
||||||
ansible.builtin.command: blkid -s UUID -o value /dev/sys/root
|
ansible.builtin.command: blkid -s UUID -o value /dev/sys/root
|
||||||
register: partitioning_uuid_root_result
|
register: partitioning_uuid_root_result
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Get UUID for LVM swap filesystem
|
- name: Get UUID for LVM swap filesystem
|
||||||
when:
|
when:
|
||||||
- filesystem != 'btrfs'
|
- system_cfg.filesystem != 'btrfs'
|
||||||
- system_cfg.features.swap.enabled | bool
|
- system_cfg.features.swap.enabled | bool
|
||||||
ansible.builtin.command: blkid -s UUID -o value /dev/sys/swap
|
ansible.builtin.command: blkid -s UUID -o value /dev/sys/swap
|
||||||
register: partitioning_uuid_swap_result
|
register: partitioning_uuid_swap_result
|
||||||
@@ -474,7 +474,7 @@
|
|||||||
|
|
||||||
- name: Get UUID for LVM home filesystem
|
- name: Get UUID for LVM home filesystem
|
||||||
when:
|
when:
|
||||||
- filesystem != 'btrfs'
|
- system_cfg.filesystem != 'btrfs'
|
||||||
- system_cfg.features.cis.enabled
|
- system_cfg.features.cis.enabled
|
||||||
ansible.builtin.command: blkid -s UUID -o value /dev/sys/home
|
ansible.builtin.command: blkid -s UUID -o value /dev/sys/home
|
||||||
register: partitioning_uuid_home_result
|
register: partitioning_uuid_home_result
|
||||||
@@ -482,7 +482,7 @@
|
|||||||
|
|
||||||
- name: Get UUID for LVM var filesystem
|
- name: Get UUID for LVM var filesystem
|
||||||
when:
|
when:
|
||||||
- filesystem != 'btrfs'
|
- system_cfg.filesystem != 'btrfs'
|
||||||
- system_cfg.features.cis.enabled
|
- system_cfg.features.cis.enabled
|
||||||
ansible.builtin.command: blkid -s UUID -o value /dev/sys/var
|
ansible.builtin.command: blkid -s UUID -o value /dev/sys/var
|
||||||
register: partitioning_uuid_var_result
|
register: partitioning_uuid_var_result
|
||||||
@@ -490,7 +490,7 @@
|
|||||||
|
|
||||||
- name: Get UUID for LVM var_log filesystem
|
- name: Get UUID for LVM var_log filesystem
|
||||||
when:
|
when:
|
||||||
- filesystem != 'btrfs'
|
- system_cfg.filesystem != 'btrfs'
|
||||||
- system_cfg.features.cis.enabled
|
- system_cfg.features.cis.enabled
|
||||||
ansible.builtin.command: blkid -s UUID -o value /dev/sys/var_log
|
ansible.builtin.command: blkid -s UUID -o value /dev/sys/var_log
|
||||||
register: partitioning_uuid_var_log_result
|
register: partitioning_uuid_var_log_result
|
||||||
@@ -498,14 +498,14 @@
|
|||||||
|
|
||||||
- name: Get UUID for LVM var_log_audit filesystem
|
- name: Get UUID for LVM var_log_audit filesystem
|
||||||
when:
|
when:
|
||||||
- filesystem != 'btrfs'
|
- system_cfg.filesystem != 'btrfs'
|
||||||
- system_cfg.features.cis.enabled
|
- system_cfg.features.cis.enabled
|
||||||
ansible.builtin.command: blkid -s UUID -o value /dev/sys/var_log_audit
|
ansible.builtin.command: blkid -s UUID -o value /dev/sys/var_log_audit
|
||||||
register: partitioning_uuid_var_log_audit_result
|
register: partitioning_uuid_var_log_audit_result
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Assign UUIDs to Variables
|
- name: Assign UUIDs to Variables
|
||||||
when: filesystem != 'btrfs'
|
when: system_cfg.filesystem != 'btrfs'
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
partitioning_uuid_root: "{{ partitioning_uuid_root_result.stdout_lines | default([]) }}"
|
partitioning_uuid_root: "{{ partitioning_uuid_root_result.stdout_lines | default([]) }}"
|
||||||
partitioning_uuid_swap: >-
|
partitioning_uuid_swap: >-
|
||||||
@@ -546,17 +546,17 @@
|
|||||||
- >-
|
- >-
|
||||||
system_cfg.features.cis.enabled or (
|
system_cfg.features.cis.enabled or (
|
||||||
not system_cfg.features.cis.enabled and (
|
not system_cfg.features.cis.enabled and (
|
||||||
(filesystem == 'btrfs' and item.path in ['/home', '/var/log', '/var/cache/pacman/pkg'])
|
(system_cfg.filesystem == 'btrfs' and item.path in ['/home', '/var/log', '/var/cache/pacman/pkg'])
|
||||||
or (item.path not in ['/home', '/var', '/var/log', '/var/log/audit', '/var/cache/pacman/pkg'])
|
or (item.path not in ['/home', '/var', '/var/log', '/var/log/audit', '/var/cache/pacman/pkg'])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
- >-
|
- >-
|
||||||
not (item.path in ['/swap', '/var/cache/pacman/pkg'] and filesystem != 'btrfs')
|
not (item.path in ['/swap', '/var/cache/pacman/pkg'] and system_cfg.filesystem != 'btrfs')
|
||||||
- system_cfg.features.swap.enabled | bool or item.path != '/swap'
|
- system_cfg.features.swap.enabled | bool or item.path != '/swap'
|
||||||
ansible.posix.mount:
|
ansible.posix.mount:
|
||||||
path: /mnt{{ item.path }}
|
path: /mnt{{ item.path }}
|
||||||
src: "{{ 'UUID=' + (partitioning_main_uuid.stdout if filesystem == 'btrfs' else item.uuid) }}"
|
src: "{{ 'UUID=' + (partitioning_main_uuid.stdout if system_cfg.filesystem == 'btrfs' else item.uuid) }}"
|
||||||
fstype: "{{ filesystem }}"
|
fstype: "{{ system_cfg.filesystem }}"
|
||||||
opts: "{{ item.opts }}"
|
opts: "{{ item.opts }}"
|
||||||
state: mounted
|
state: mounted
|
||||||
loop:
|
loop:
|
||||||
@@ -565,7 +565,7 @@
|
|||||||
opts: >-
|
opts: >-
|
||||||
{{
|
{{
|
||||||
'defaults'
|
'defaults'
|
||||||
if filesystem != 'btrfs'
|
if system_cfg.filesystem != 'btrfs'
|
||||||
else [
|
else [
|
||||||
'rw', 'relatime', partitioning_btrfs_compress_opt, 'ssd', 'space_cache=v2',
|
'rw', 'relatime', partitioning_btrfs_compress_opt, 'ssd', 'space_cache=v2',
|
||||||
'discard=async', 'subvol=@'
|
'discard=async', 'subvol=@'
|
||||||
@@ -584,7 +584,7 @@
|
|||||||
opts: >-
|
opts: >-
|
||||||
{{
|
{{
|
||||||
'defaults,nosuid,nodev'
|
'defaults,nosuid,nodev'
|
||||||
if filesystem != 'btrfs'
|
if system_cfg.filesystem != 'btrfs'
|
||||||
else [
|
else [
|
||||||
'rw', 'nosuid', 'nodev', 'relatime', partitioning_btrfs_compress_opt, 'ssd',
|
'rw', 'nosuid', 'nodev', 'relatime', partitioning_btrfs_compress_opt, 'ssd',
|
||||||
'space_cache=v2', 'discard=async', 'subvol=@home'
|
'space_cache=v2', 'discard=async', 'subvol=@home'
|
||||||
@@ -595,7 +595,7 @@
|
|||||||
opts: >-
|
opts: >-
|
||||||
{{
|
{{
|
||||||
'defaults,nosuid,nodev'
|
'defaults,nosuid,nodev'
|
||||||
if filesystem != 'btrfs'
|
if system_cfg.filesystem != 'btrfs'
|
||||||
else [
|
else [
|
||||||
'rw', 'nosuid', 'nodev', 'relatime', partitioning_btrfs_compress_opt, 'ssd',
|
'rw', 'nosuid', 'nodev', 'relatime', partitioning_btrfs_compress_opt, 'ssd',
|
||||||
'space_cache=v2', 'discard=async', 'subvol=@var'
|
'space_cache=v2', 'discard=async', 'subvol=@var'
|
||||||
@@ -606,7 +606,7 @@
|
|||||||
opts: >-
|
opts: >-
|
||||||
{{
|
{{
|
||||||
'defaults,nosuid,nodev,noexec'
|
'defaults,nosuid,nodev,noexec'
|
||||||
if filesystem != 'btrfs'
|
if system_cfg.filesystem != 'btrfs'
|
||||||
else [
|
else [
|
||||||
'rw', 'nosuid', 'nodev', 'noexec', 'relatime', partitioning_btrfs_compress_opt,
|
'rw', 'nosuid', 'nodev', 'noexec', 'relatime', partitioning_btrfs_compress_opt,
|
||||||
'ssd', 'space_cache=v2', 'discard=async', 'subvol=@var_log'
|
'ssd', 'space_cache=v2', 'discard=async', 'subvol=@var_log'
|
||||||
@@ -617,7 +617,7 @@
|
|||||||
opts: >-
|
opts: >-
|
||||||
{{
|
{{
|
||||||
'defaults,nosuid,nodev,noexec'
|
'defaults,nosuid,nodev,noexec'
|
||||||
if filesystem != 'btrfs'
|
if system_cfg.filesystem != 'btrfs'
|
||||||
else [
|
else [
|
||||||
'rw', 'nosuid', 'nodev', 'noexec', 'relatime', partitioning_btrfs_compress_opt,
|
'rw', 'nosuid', 'nodev', 'noexec', 'relatime', partitioning_btrfs_compress_opt,
|
||||||
'ssd', 'space_cache=v2', 'discard=async', 'subvol=@pkg'
|
'ssd', 'space_cache=v2', 'discard=async', 'subvol=@pkg'
|
||||||
@@ -628,7 +628,7 @@
|
|||||||
opts: >-
|
opts: >-
|
||||||
{{
|
{{
|
||||||
'defaults,nosuid,nodev,noexec'
|
'defaults,nosuid,nodev,noexec'
|
||||||
if filesystem != 'btrfs'
|
if system_cfg.filesystem != 'btrfs'
|
||||||
else [
|
else [
|
||||||
'rw', 'nosuid', 'nodev', 'noexec', 'relatime', partitioning_btrfs_compress_opt,
|
'rw', 'nosuid', 'nodev', 'noexec', 'relatime', partitioning_btrfs_compress_opt,
|
||||||
'ssd', 'space_cache=v2', 'discard=async', 'subvol=@var_log_audit'
|
'ssd', 'space_cache=v2', 'discard=async', 'subvol=@var_log_audit'
|
||||||
@@ -655,7 +655,7 @@
|
|||||||
when: system_cfg.features.swap.enabled | bool
|
when: system_cfg.features.swap.enabled | bool
|
||||||
vars:
|
vars:
|
||||||
partitioning_swap_cmd: >-
|
partitioning_swap_cmd: >-
|
||||||
{{ 'swapon /mnt/swap/swapfile' if filesystem == 'btrfs' else 'swapon -U ' + partitioning_uuid_swap[0] }}
|
{{ 'swapon /mnt/swap/swapfile' if system_cfg.filesystem == 'btrfs' else 'swapon -U ' + partitioning_uuid_swap[0] }}
|
||||||
ansible.builtin.command: "{{ partitioning_swap_cmd }}"
|
ansible.builtin.command: "{{ partitioning_swap_cmd }}"
|
||||||
register: partitioning_swap_activate_result
|
register: partitioning_swap_activate_result
|
||||||
changed_when: partitioning_swap_activate_result.rc == 0
|
changed_when: partitioning_swap_activate_result.rc == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user