From 6b1686e652cb63a2eb8c9ca0a0ae77abac33ccbb Mon Sep 17 00:00:00 2001 From: Sandwich Date: Sun, 22 Feb 2026 02:27:46 +0100 Subject: [PATCH] refactor(bootstrap,configuration): add per-role _normalize.yml for platform resolution --- roles/bootstrap/tasks/_normalize.yml | 24 ++++++++++++++++++++++++ roles/bootstrap/tasks/main.yml | 7 +++++-- roles/configuration/tasks/_normalize.yml | 16 ++++++++++++++++ roles/configuration/tasks/main.yml | 5 ++--- 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 roles/bootstrap/tasks/_normalize.yml create mode 100644 roles/configuration/tasks/_normalize.yml diff --git a/roles/bootstrap/tasks/_normalize.yml b/roles/bootstrap/tasks/_normalize.yml new file mode 100644 index 0000000..ca5edfe --- /dev/null +++ b/roles/bootstrap/tasks/_normalize.yml @@ -0,0 +1,24 @@ +--- +# Resolve the OS-specific variable namespace and task file for the bootstrap role. +- name: Validate OS is supported for bootstrap + ansible.builtin.assert: + that: + - os is defined + - os in bootstrap_os_task_map + fail_msg: >- + Unsupported OS '{{ os | default("undefined") }}' for bootstrap. + Supported: {{ bootstrap_os_task_map | dict2items | map(attribute='key') | join(', ') }} + quiet: true + vars: + bootstrap_os_task_map: + almalinux: _dnf_family.yml + alpine: alpine.yml + archlinux: archlinux.yml + debian: debian.yml + fedora: _dnf_family.yml + opensuse: opensuse.yml + rocky: _dnf_family.yml + rhel: rhel.yml + ubuntu: ubuntu.yml + ubuntu-lts: ubuntu.yml + void: void.yml diff --git a/roles/bootstrap/tasks/main.yml b/roles/bootstrap/tasks/main.yml index 7c1928b..d6b50ca 100644 --- a/roles/bootstrap/tasks/main.yml +++ b/roles/bootstrap/tasks/main.yml @@ -1,6 +1,9 @@ --- +- name: Normalize bootstrap + ansible.builtin.import_tasks: _normalize.yml + - name: Create API filesystem mountpoints in installroot - when: is_rhel | bool + when: os_family == 'RedHat' ansible.builtin.file: path: "/mnt/{{ item }}" state: directory @@ -11,7 +14,7 @@ - sys - name: Mount API filesystems into installroot - when: is_rhel | bool + when: os_family == 'RedHat' ansible.posix.mount: src: "{{ item.src }}" path: "/mnt/{{ item.path }}" diff --git a/roles/configuration/tasks/_normalize.yml b/roles/configuration/tasks/_normalize.yml new file mode 100644 index 0000000..7ff6956 --- /dev/null +++ b/roles/configuration/tasks/_normalize.yml @@ -0,0 +1,16 @@ +--- +# Resolve platform-specific configuration for the target OS family. +# Sets _configuration_platform from configuration_platform_config[os_family]. +- name: Resolve platform-specific configuration + ansible.builtin.assert: + that: + - os_family is defined + - os_family in configuration_platform_config + fail_msg: >- + Unsupported os_family '{{ os_family | default("undefined") }}'. + Extend configuration_platform_config in vars/main.yml. + quiet: true + +- name: Set platform configuration + ansible.builtin.set_fact: + _configuration_platform: "{{ configuration_platform_config[os_family] }}" diff --git a/roles/configuration/tasks/main.yml b/roles/configuration/tasks/main.yml index de6c9ff..29fa9e3 100644 --- a/roles/configuration/tasks/main.yml +++ b/roles/configuration/tasks/main.yml @@ -1,7 +1,6 @@ --- -- name: Resolve platform-specific configuration - ansible.builtin.set_fact: - _configuration_platform: "{{ configuration_platform_config[os_family] }}" +- name: Normalize configuration + ansible.builtin.import_tasks: _normalize.yml - name: Include configuration tasks when: configuration_task.when | default(true)