refactor(bootstrap): restructure package lists to self-contained per-OS dicts with base/extra/conditional
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
---
|
||||
- name: Bootstrap Alpine Linux
|
||||
vars:
|
||||
bootstrap_alpine_packages: >-
|
||||
_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
||||
_base_packages: "{{ _config.base | join(' ') }}"
|
||||
_extra_packages: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key) | reject('equalto', '') | join(' ')
|
||||
((_config.extra | default([])) + (_config.conditional | default([])))
|
||||
| reject('equalto', '')
|
||||
| join(' ')
|
||||
}}
|
||||
block:
|
||||
- name: Install Alpine Linux packages
|
||||
- name: Install Alpine Linux base
|
||||
ansible.builtin.command: >
|
||||
apk --root /mnt --no-cache add alpine-base
|
||||
apk --root /mnt --no-cache add {{ _base_packages }}
|
||||
register: bootstrap_alpine_bootstrap_result
|
||||
changed_when: bootstrap_alpine_bootstrap_result.rc == 0
|
||||
|
||||
- name: Install extra packages
|
||||
when: bootstrap_alpine_packages | length > 0
|
||||
when: _extra_packages | trim | length > 0
|
||||
ansible.builtin.command: >
|
||||
apk --root /mnt add {{ bootstrap_alpine_packages }}
|
||||
apk --root /mnt add {{ _extra_packages }}
|
||||
register: bootstrap_alpine_extra_result
|
||||
changed_when: bootstrap_alpine_extra_result.rc == 0
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
---
|
||||
- name: Bootstrap ArchLinux
|
||||
vars:
|
||||
_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
||||
bootstrap_archlinux_packages: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key)
|
||||
((_config.base | default([])) + (_config.conditional | default([])))
|
||||
| reject('equalto', '')
|
||||
| list
|
||||
}}
|
||||
ansible.builtin.command: >-
|
||||
pacstrap /mnt {{ bootstrap_archlinux_packages | reject('equalto', '') | join(' ') }} --asexplicit
|
||||
pacstrap /mnt {{ bootstrap_archlinux_packages | join(' ') }} --asexplicit
|
||||
register: bootstrap_result
|
||||
changed_when: bootstrap_result.rc == 0
|
||||
|
||||
@@ -10,53 +10,33 @@
|
||||
else 'sid' if (os_version | string) == 'unstable'
|
||||
else 'trixie'
|
||||
}}
|
||||
bootstrap_debian_package_config: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key)
|
||||
}}
|
||||
bootstrap_debian_base_packages: >-
|
||||
{{
|
||||
bootstrap_debian_package_config.base
|
||||
| default([])
|
||||
| reject('equalto', '')
|
||||
| list
|
||||
}}
|
||||
bootstrap_debian_extra_packages: >-
|
||||
{{
|
||||
bootstrap_debian_package_config.extra
|
||||
| default([])
|
||||
| reject('equalto', '')
|
||||
| list
|
||||
}}
|
||||
bootstrap_debian_base_csv: "{{ bootstrap_debian_base_packages | join(',') }}"
|
||||
_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
||||
bootstrap_debian_base_csv: "{{ (['ca-certificates'] + _config.base) | unique | join(',') }}"
|
||||
bootstrap_debian_extra_args: >-
|
||||
{{
|
||||
bootstrap_debian_extra_packages
|
||||
((_config.extra | default([])) + (_config.conditional | default([])))
|
||||
| reject('equalto', '')
|
||||
| join(' ')
|
||||
}}
|
||||
block:
|
||||
- name: Validate Debian package configuration
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- bootstrap_debian_package_config is mapping
|
||||
- bootstrap_debian_package_config.base is defined
|
||||
- bootstrap_debian_package_config.base is sequence
|
||||
- bootstrap_debian_package_config.base is not string
|
||||
- bootstrap_debian_package_config.extra is defined
|
||||
- bootstrap_debian_package_config.extra is sequence
|
||||
- bootstrap_debian_package_config.extra is not string
|
||||
fail_msg: "bootstrap package definition for {{ bootstrap_var_key }} must be a mapping with base/extra lists."
|
||||
- _config is mapping
|
||||
- _config.base is sequence
|
||||
- _config.extra is sequence
|
||||
fail_msg: "{{ bootstrap_var_key }} must be a dict with base/extra/conditional keys."
|
||||
quiet: true
|
||||
|
||||
- name: Install Debian base system
|
||||
ansible.builtin.command: >-
|
||||
debootstrap --include={{ bootstrap_debian_base_csv }}
|
||||
{{ bootstrap_debian_release }} /mnt http://deb.debian.org/debian/
|
||||
{{ bootstrap_debian_release }} /mnt https://deb.debian.org/debian/
|
||||
register: bootstrap_debian_base_result
|
||||
changed_when: bootstrap_debian_base_result.rc == 0
|
||||
|
||||
- name: Install extra packages
|
||||
when: bootstrap_debian_extra_packages | length > 0
|
||||
when: bootstrap_debian_extra_args | trim | length > 0
|
||||
ansible.builtin.command: "{{ chroot_command }} apt install -y {{ bootstrap_debian_extra_args }}"
|
||||
register: bootstrap_debian_extra_result
|
||||
changed_when: bootstrap_debian_extra_result.rc == 0
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
---
|
||||
- name: Bootstrap openSUSE
|
||||
vars:
|
||||
bootstrap_opensuse_packages: >-
|
||||
_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
||||
_base_patterns: "{{ _config.base | join(' ') }}"
|
||||
_extra_packages: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key) | reject('equalto', '') | join(' ')
|
||||
((_config.extra | default([])) + (_config.conditional | default([])))
|
||||
| reject('equalto', '')
|
||||
| join(' ')
|
||||
}}
|
||||
block:
|
||||
- name: Install openSUSE base packages
|
||||
- name: Install openSUSE base patterns
|
||||
ansible.builtin.command: >
|
||||
zypper --root /mnt --non-interactive install -t pattern patterns-base-base
|
||||
zypper --root /mnt --non-interactive install -t pattern {{ _base_patterns }}
|
||||
register: bootstrap_opensuse_base_result
|
||||
changed_when: bootstrap_opensuse_base_result.rc == 0
|
||||
|
||||
- name: Install openSUSE extra packages
|
||||
when: bootstrap_opensuse_packages | length > 0
|
||||
- name: Install extra packages
|
||||
when: _extra_packages | trim | length > 0
|
||||
ansible.builtin.command: >
|
||||
zypper --root /mnt --non-interactive install {{ bootstrap_opensuse_packages }}
|
||||
zypper --root /mnt --non-interactive install {{ _extra_packages }}
|
||||
register: bootstrap_opensuse_extra_result
|
||||
changed_when: bootstrap_opensuse_extra_result.rc == 0
|
||||
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
---
|
||||
- name: Bootstrap RHEL System
|
||||
vars:
|
||||
_rhel_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
||||
_rhel_repos: "{{ _rhel_config.repos | map('regex_replace', '^', '--repo=') | join(' ') }}"
|
||||
_rhel_groups: "{{ _rhel_config.base | join(' ') }}"
|
||||
_rhel_extra: >-
|
||||
{{
|
||||
((_rhel_config.extra | default([])) + (_rhel_config.conditional | default([])))
|
||||
| reject('equalto', '')
|
||||
| join(' ')
|
||||
}}
|
||||
block:
|
||||
- name: Install base packages in chroot environment
|
||||
ansible.builtin.command: >-
|
||||
dnf --releasever={{ os_version_major }} --repo=rhel{{ os_version_major }}-baseos
|
||||
dnf --releasever={{ os_version_major }} {{ _rhel_repos }}
|
||||
--installroot=/mnt
|
||||
--setopt=install_weak_deps=False --setopt=optional_metadata_types=filelists
|
||||
groupinstall -y core base standard
|
||||
groupinstall -y {{ _rhel_groups }}
|
||||
register: bootstrap_result
|
||||
changed_when: bootstrap_result.rc == 0
|
||||
failed_when:
|
||||
@@ -40,15 +50,8 @@
|
||||
remote_src: true
|
||||
|
||||
- name: Install additional packages in chroot
|
||||
vars:
|
||||
bootstrap_rhel_extra: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key)
|
||||
| reject('equalto', '')
|
||||
| join(' ')
|
||||
}}
|
||||
ansible.builtin.command: >-
|
||||
{{ chroot_command }} dnf --releasever={{ os_version_major }}
|
||||
--setopt=install_weak_deps=False install -y {{ bootstrap_rhel_extra }}
|
||||
--setopt=install_weak_deps=False install -y {{ _rhel_extra }}
|
||||
register: bootstrap_result
|
||||
changed_when: bootstrap_result.rc == 0
|
||||
|
||||
@@ -6,38 +6,22 @@
|
||||
ubuntu: plucky
|
||||
ubuntu-lts: noble
|
||||
bootstrap_ubuntu_release: "{{ bootstrap_ubuntu_release_map[os] | default('noble') }}"
|
||||
bootstrap_ubuntu_package_config: >-
|
||||
_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
||||
bootstrap_ubuntu_base_csv: "{{ (['ca-certificates'] + _config.base) | unique | join(',') }}"
|
||||
bootstrap_ubuntu_extra_args: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key)
|
||||
}}
|
||||
bootstrap_ubuntu_base_packages: >-
|
||||
{{
|
||||
bootstrap_ubuntu_package_config.base
|
||||
| default([])
|
||||
((_config.extra | default([])) + (_config.conditional | default([])))
|
||||
| reject('equalto', '')
|
||||
| list
|
||||
| join(' ')
|
||||
}}
|
||||
bootstrap_ubuntu_extra_packages: >-
|
||||
{{
|
||||
bootstrap_ubuntu_package_config.extra
|
||||
| default([])
|
||||
| reject('equalto', '')
|
||||
| list
|
||||
}}
|
||||
bootstrap_ubuntu_base_csv: "{{ bootstrap_ubuntu_base_packages | join(',') }}"
|
||||
bootstrap_ubuntu_extra: "{{ bootstrap_ubuntu_extra_packages | join(' ') }}"
|
||||
block:
|
||||
- name: Validate Ubuntu package configuration
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- bootstrap_ubuntu_package_config is mapping
|
||||
- bootstrap_ubuntu_package_config.base is defined
|
||||
- bootstrap_ubuntu_package_config.base is sequence
|
||||
- bootstrap_ubuntu_package_config.base is not string
|
||||
- bootstrap_ubuntu_package_config.extra is defined
|
||||
- bootstrap_ubuntu_package_config.extra is sequence
|
||||
- bootstrap_ubuntu_package_config.extra is not string
|
||||
fail_msg: "bootstrap package definition for {{ bootstrap_var_key }} must be a mapping with base/extra lists."
|
||||
- _config is mapping
|
||||
- _config.base is sequence
|
||||
- _config.extra is sequence
|
||||
fail_msg: "{{ bootstrap_var_key }} must be a dict with base/extra/conditional keys."
|
||||
quiet: true
|
||||
|
||||
- name: Install Ubuntu base system
|
||||
@@ -46,7 +30,7 @@
|
||||
--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg
|
||||
--include={{ bootstrap_ubuntu_base_csv }}
|
||||
{{ bootstrap_ubuntu_release }} /mnt
|
||||
http://archive.ubuntu.com/ubuntu/
|
||||
https://archive.ubuntu.com/ubuntu/
|
||||
register: bootstrap_ubuntu_base_result
|
||||
changed_when: bootstrap_ubuntu_base_result.rc == 0
|
||||
|
||||
@@ -62,7 +46,7 @@
|
||||
changed_when: bootstrap_ubuntu_update_result.rc == 0
|
||||
|
||||
- name: Install extra packages
|
||||
when: bootstrap_ubuntu_extra_packages | length > 0
|
||||
ansible.builtin.command: "{{ chroot_command }} apt install -y {{ bootstrap_ubuntu_extra }}"
|
||||
when: bootstrap_ubuntu_extra_args | trim | length > 0
|
||||
ansible.builtin.command: "{{ chroot_command }} apt install -y {{ bootstrap_ubuntu_extra_args }}"
|
||||
register: bootstrap_ubuntu_extra_result
|
||||
changed_when: bootstrap_ubuntu_extra_result.rc == 0
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
---
|
||||
- name: Bootstrap Void Linux
|
||||
vars:
|
||||
bootstrap_void_packages: >-
|
||||
_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
||||
_base_packages: "{{ _config.base | join(' ') }}"
|
||||
_extra_packages: >-
|
||||
{{
|
||||
lookup('vars', bootstrap_var_key) | reject('equalto', '') | join(' ')
|
||||
((_config.extra | default([])) + (_config.conditional | default([])))
|
||||
| reject('equalto', '')
|
||||
| join(' ')
|
||||
}}
|
||||
block:
|
||||
- name: Install Void Linux base packages
|
||||
- name: Install Void Linux base
|
||||
ansible.builtin.command: >
|
||||
xbps-install -Sy -r /mnt -R https://repo-default.voidlinux.org/current void-repo-nonfree base-system
|
||||
xbps-install -Sy -r /mnt -R https://repo-default.voidlinux.org/current {{ _base_packages }}
|
||||
register: bootstrap_void_base_result
|
||||
changed_when: bootstrap_void_base_result.rc == 0
|
||||
|
||||
- name: Install extra packages
|
||||
when: bootstrap_void_packages | length > 0
|
||||
when: _extra_packages | trim | length > 0
|
||||
ansible.builtin.command: >
|
||||
xbps-install -Su -r /mnt {{ bootstrap_void_packages }}
|
||||
xbps-install -Su -r /mnt {{ _extra_packages }}
|
||||
register: bootstrap_void_extra_result
|
||||
changed_when: bootstrap_void_extra_result.rc == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user