refactor(bootstrap): standardize patterns, extract common logic, remove dead code
This commit is contained in:
@@ -1,45 +1,17 @@
|
||||
---
|
||||
- name: Run OS-specific bootstrap process
|
||||
vars:
|
||||
bootstrap_os_key: "{{ (os_resolved | default(os)) | lower }}"
|
||||
bootstrap_var_key: "{{ 'bootstrap_' + ((os_resolved | default(os)) | lower | replace('-', '_')) }}"
|
||||
block:
|
||||
- name: Include AlmaLinux bootstrap tasks
|
||||
when: bootstrap_os_key in ['almalinux', 'almalinux8', 'almalinux9', 'almalinux10']
|
||||
ansible.builtin.include_tasks: almalinux.yml
|
||||
|
||||
- name: Include Alpine bootstrap tasks
|
||||
when: bootstrap_os_key == 'alpine'
|
||||
ansible.builtin.include_tasks: alpine.yml
|
||||
|
||||
- name: Include ArchLinux bootstrap tasks
|
||||
when: bootstrap_os_key == 'archlinux'
|
||||
ansible.builtin.include_tasks: archlinux.yml
|
||||
|
||||
- name: Include Debian bootstrap tasks
|
||||
when: bootstrap_os_key in ['debian10', 'debian11', 'debian12', 'debian13', 'debianunstable']
|
||||
ansible.builtin.include_tasks: debian.yml
|
||||
|
||||
- name: Include Fedora bootstrap tasks
|
||||
when: bootstrap_os_key in ['fedora', 'fedora40', 'fedora41', 'fedora42', 'fedora43']
|
||||
ansible.builtin.include_tasks: fedora.yml
|
||||
|
||||
- name: Include openSUSE bootstrap tasks
|
||||
when: bootstrap_os_key == 'opensuse'
|
||||
ansible.builtin.include_tasks: opensuse.yml
|
||||
|
||||
- name: Include Rocky bootstrap tasks
|
||||
when: bootstrap_os_key in ['rocky', 'rocky8', 'rocky9', 'rocky10']
|
||||
ansible.builtin.include_tasks: rocky.yml
|
||||
|
||||
- name: Include RHEL bootstrap tasks
|
||||
when: bootstrap_os_key in ['rhel8', 'rhel9', 'rhel10']
|
||||
ansible.builtin.include_tasks: rhel.yml
|
||||
|
||||
- name: Include Ubuntu bootstrap tasks
|
||||
when: bootstrap_os_key in ['ubuntu', 'ubuntu-lts']
|
||||
ansible.builtin.include_tasks: ubuntu.yml
|
||||
|
||||
- name: Include Void bootstrap tasks
|
||||
when: bootstrap_os_key == 'void'
|
||||
ansible.builtin.include_tasks: void.yml
|
||||
bootstrap_os_task_map:
|
||||
almalinux: almalinux.yml
|
||||
alpine: alpine.yml
|
||||
archlinux: archlinux.yml
|
||||
debian: debian.yml
|
||||
fedora: fedora.yml
|
||||
opensuse: opensuse.yml
|
||||
rocky: rocky.yml
|
||||
rhel: rhel.yml
|
||||
ubuntu: ubuntu.yml
|
||||
ubuntu-lts: ubuntu.yml
|
||||
void: void.yml
|
||||
bootstrap_var_key: "{{ 'bootstrap_' + (os | replace('-lts', '') | replace('-', '_')) }}"
|
||||
ansible.builtin.include_tasks: "{{ bootstrap_os_task_map[os] }}"
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
- name: Bootstrap RHEL System
|
||||
block:
|
||||
- name: Install base packages in chroot environment
|
||||
vars:
|
||||
bootstrap_rhel_release: "{{ bootstrap_os_key | replace('rhel', '') }}"
|
||||
ansible.builtin.command: >-
|
||||
dnf --releasever={{ bootstrap_rhel_release }} --repo={{ bootstrap_os_key }}-baseos
|
||||
dnf --releasever={{ os_version_major }} --repo=rhel{{ os_version_major }}-baseos
|
||||
--installroot=/mnt
|
||||
--setopt=install_weak_deps=False --setopt=optional_metadata_types=filelists
|
||||
groupinstall -y core base standard
|
||||
@@ -39,14 +37,13 @@
|
||||
|
||||
- name: Copy RHEL repo file into chroot environment
|
||||
ansible.builtin.copy:
|
||||
src: /etc/yum.repos.d/{{ bootstrap_os_key }}.repo
|
||||
src: /etc/yum.repos.d/rhel.repo
|
||||
dest: /mnt/etc/yum.repos.d/redhat.repo
|
||||
mode: "0644"
|
||||
remote_src: true
|
||||
|
||||
- name: Install additional packages in chroot
|
||||
vars:
|
||||
bootstrap_rhel_release: "{{ bootstrap_os_key | replace('rhel', '') }}"
|
||||
bootstrap_rhel_extra: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key)
|
||||
@@ -54,7 +51,7 @@
|
||||
| join(' ')
|
||||
}}
|
||||
ansible.builtin.command: >-
|
||||
{{ chroot_command }} dnf --releasever={{ bootstrap_rhel_release }}
|
||||
{{ chroot_command }} dnf --releasever={{ os_version_major }}
|
||||
--setopt=install_weak_deps=False install -y {{ bootstrap_rhel_extra }}
|
||||
register: bootstrap_result
|
||||
changed_when: bootstrap_result.rc == 0
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
- name: Bootstrap Ubuntu System
|
||||
vars:
|
||||
bootstrap_ubuntu_release: >-
|
||||
{{ 'plucky' if bootstrap_os_key == 'ubuntu' else 'noble' }}
|
||||
{{ 'plucky' if os == 'ubuntu' else 'noble' }}
|
||||
bootstrap_ubuntu_package_config: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key)
|
||||
|
||||
Reference in New Issue
Block a user