system_baseline_essential_packages and system_baseline_remove_packages replace the whole list, and so does a list inside system_baseline_profile_overrides, so adding one package meant repeating the profile's list and keeping it in step with every release. system_baseline_extra_packages and system_baseline_extra_remove_packages (lists, default empty) append to the resolved lists. The tmux and unattended-upgrades checks read the combined list, so an extra tmux or unattended-upgrades enables the matching task like a profile package. Items must be Debian package names: a null item would have become the package "None", and apt reads a trailing minus (jq-) as a removal. A package that one input installs and another purges stops the run before any change; only overlaps that involve an extra are checked, so a consumer's own overlap between the resolved lists behaves as before. A flat input that is a plain string still counts as a one-item list. With both inputs left at their default the role behaves as before. Closes #399 Assisted-by: Claude Code:claude-sonnet-5-5
129 lines
6.8 KiB
YAML
129 lines
6.8 KiB
YAML
---
|
|
# Required input with no default: the role does not read a global such as system_type;
|
|
# the inventory maps it onto system_baseline_system_type.
|
|
- name: Require system_baseline_system_type
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_system_type is defined
|
|
fail_msg: >-
|
|
system_baseline_system_type is required and has no default. Set it in
|
|
the play or the inventory.
|
|
tags: always
|
|
|
|
- name: Validate system_baseline_system_type variable
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_system_type in ['ubuntu_vm', 'ubuntu_lxc', 'pve']
|
|
fail_msg: "system_baseline_system_type '{{ system_baseline_system_type }}' is invalid. Must be: ubuntu_vm, ubuntu_lxc, pve."
|
|
success_msg: "system_baseline_system_type '{{ system_baseline_system_type }}' is valid."
|
|
tags: always
|
|
|
|
# \Z, not $: Python's `$` also matches before a final newline, which a YAML block scalar would add. Not inside a double-quoted
|
|
# YAML scalar, where \Z is an invalid escape. The types and required keys are checked by meta/argument_specs.yml.
|
|
- name: Validate the tmux session and windows
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_tmux_session is match('^[A-Za-z0-9_-]{1,32}\Z')
|
|
- system_baseline_tmux_windows | map(attribute='name') | select('match', '^[A-Za-z0-9_-]{1,32}\Z') | list | length
|
|
== system_baseline_tmux_windows | length
|
|
- system_baseline_tmux_windows | map(attribute='command') | select('match', '^[^\n\r]+\Z') | list | length
|
|
== system_baseline_tmux_windows | length
|
|
fail_msg: >-
|
|
system_baseline_tmux_session must be 1-32 characters of A-Z a-z 0-9 _ - ; every system_baseline_tmux_windows entry needs
|
|
a name (same characters) and a one-line command.
|
|
quiet: true
|
|
when: system_baseline_tmux_autostart | bool
|
|
tags: always
|
|
|
|
- name: Validate the apt upgrade mode
|
|
ansible.builtin.import_tasks: validate_apt_upgrade.yml
|
|
tags: always
|
|
|
|
- name: Validate the apt scratch directory
|
|
ansible.builtin.import_tasks: validate_apt_tmpdir.yml
|
|
tags: always
|
|
|
|
- name: Validate the reboot inputs
|
|
ansible.builtin.import_tasks: validate_reboot.yml
|
|
tags: always
|
|
|
|
# The value is written into a unit file: one line, starting with a digit, so no line break can add a second directive. systemd itself
|
|
# refuses a value it cannot parse (it ignores the setting and logs it).
|
|
- name: Validate the apt-daily start timeout
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_apt_daily_timeout is string
|
|
- system_baseline_apt_daily_timeout == '' or system_baseline_apt_daily_timeout is match('^(infinity|[0-9][0-9A-Za-z. ]{0,63})\Z')
|
|
fail_msg: >-
|
|
system_baseline_apt_daily_timeout must be empty or a systemd time span on one line, for example 1h or 90min
|
|
(quote a bare number: a plain 60 is not a string).
|
|
quiet: true
|
|
tags: always
|
|
|
|
# Each package pattern is written inside a double-quoted apt.conf string, like the origins below: the same characters are refused.
|
|
- name: Validate the unattended-upgrades package blacklist
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_unattended_upgrade_package_blacklist is sequence
|
|
- system_baseline_unattended_upgrade_package_blacklist is not string
|
|
- system_baseline_unattended_upgrade_package_blacklist is not mapping
|
|
- system_baseline_unattended_upgrade_package_blacklist | select('string') | select('match', '^[^"\\\\\n\r]+\Z') | list | length
|
|
== system_baseline_unattended_upgrade_package_blacklist | length
|
|
fail_msg: >-
|
|
system_baseline_unattended_upgrade_package_blacklist must be a list of non-empty one-line strings without a double quote
|
|
or a backslash.
|
|
quiet: true
|
|
tags: always
|
|
|
|
# The extras are appended to the resolved lists. An item must be a Debian package name (policy: lower-case letters, digits, + - . , two or
|
|
# more characters, starting with a letter or digit), and not end in a minus: apt reads `jq-` as "remove jq", and a null item would become the
|
|
# package "None". A bare string is rejected here as it is for the blacklist. A package that one input installs and another purges would be
|
|
# installed and removed on every run, so it stops the run; only overlaps that involve an extra are checked, the resolved lists themselves
|
|
# are the consumer's.
|
|
- name: Validate the extra packages
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_extra_packages is sequence
|
|
- system_baseline_extra_packages is not string
|
|
- system_baseline_extra_packages is not mapping
|
|
- system_baseline_extra_packages | select('string') | select('match', '^[a-z0-9][a-z0-9+.-]*[a-z0-9+.]\Z') | list | length
|
|
== system_baseline_extra_packages | length
|
|
- system_baseline_extra_remove_packages is sequence
|
|
- system_baseline_extra_remove_packages is not string
|
|
- system_baseline_extra_remove_packages is not mapping
|
|
- system_baseline_extra_remove_packages | select('string') | select('match', '^[a-z0-9][a-z0-9+.-]*[a-z0-9+.]\Z') | list | length
|
|
== system_baseline_extra_remove_packages | length
|
|
fail_msg: >-
|
|
system_baseline_extra_packages and system_baseline_extra_remove_packages must be lists of package names: lower-case letters,
|
|
digits, + - . only, two or more characters, starting with a letter or digit and not ending in a minus.
|
|
quiet: true
|
|
tags: always
|
|
|
|
- name: Refuse a package that is both installed and purged
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_extra_packages | intersect(__system_baseline_purge_packages) | length == 0
|
|
- system_baseline_extra_remove_packages | intersect(__system_baseline_install_packages) | length == 0
|
|
fail_msg: >-
|
|
A package is both installed and purged. system_baseline_extra_packages must not name a package of system_baseline_remove_packages or
|
|
system_baseline_extra_remove_packages, and system_baseline_extra_remove_packages must not name a package of
|
|
system_baseline_essential_packages. Found: {{ (system_baseline_extra_packages | intersect(__system_baseline_purge_packages)) +
|
|
(system_baseline_extra_remove_packages | intersect(__system_baseline_install_packages)) }}.
|
|
quiet: true
|
|
tags: always
|
|
|
|
# Each origin is written inside a double-quoted apt.conf string: a quote or a line break would end it, a backslash could escape.
|
|
- name: Validate the unattended-upgrades origins
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_unattended_upgrade_origins is sequence
|
|
- system_baseline_unattended_upgrade_origins is not string
|
|
- system_baseline_unattended_upgrade_origins is not mapping
|
|
- system_baseline_unattended_upgrade_origins | select('string') | select('match', '^[^"\\\\\n\r]+\Z') | list | length
|
|
== system_baseline_unattended_upgrade_origins | length
|
|
fail_msg: >-
|
|
system_baseline_unattended_upgrade_origins must be a list of non-empty one-line strings without a double quote
|
|
or a backslash.
|
|
quiet: true
|
|
tags: always
|