fix(global_defaults): read dict2items key and key enrichment on os

This commit is contained in:
2026-09-15 21:05:37 +02:00
parent 96220d424e
commit 9cc0c704a7
2 changed files with 7 additions and 7 deletions
+3 -1
View File
@@ -35,10 +35,12 @@
}, recursive=True) }, recursive=True)
}} }}
# Keyed on os, not hostname: inventories set hostname themselves, and doing so
# would otherwise skip enrichment and leave os undefined for validation.
- name: Check if pre-computed system_cfg needs enrichment - name: Check if pre-computed system_cfg needs enrichment
when: system_cfg is defined when: system_cfg is defined
ansible.builtin.set_fact: ansible.builtin.set_fact:
_bootstrap_needs_enrichment: "{{ hostname is not defined }}" _bootstrap_needs_enrichment: "{{ os is not defined }}"
- name: Merge pre-computed system_cfg with bootstrap system_defaults - name: Merge pre-computed system_cfg with bootstrap system_defaults
when: when:
+4 -6
View File
@@ -317,7 +317,7 @@
_autologin: "{{ system_cfg.features.desktop.autologin | default(false) }}" _autologin: "{{ system_cfg.features.desktop.autologin | default(false) }}"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- _autologin is boolean and not _autologin or (_autologin is string and _autologin | length > 0 and _autologin in system_cfg.users) - _autologin is boolean and not _autologin or (_autologin is string and _autologin | length > 0 and _autologin in system_cfg.users | map(attribute='name'))
fail_msg: >- fail_msg: >-
desktop.autologin must be false or a username string present in desktop.autologin must be false or a username string present in
system.users; got '{{ _autologin }}'. Bool true is not accepted - the system.users; got '{{ _autologin }}'. Bool true is not accepted - the
@@ -355,14 +355,12 @@
- name: Validate at least one user with a password is defined - name: Validate at least one user with a password is defined
vars: vars:
_pw_users: "{{ system_cfg.users | dict2items | selectattr('value.password', 'defined') | list }}" _pw_users: "{{ system_cfg.users | selectattr('password', 'defined') | map(attribute='password') | map('string') | reject('equalto', '') | list }}"
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- system_cfg.users | default({}) | length > 0 - system_cfg.users | default([]) | length > 0
- _pw_users | length > 0 - _pw_users | length > 0
- _pw_users[0].key | string | length > 0 fail_msg: "At least one user with a non-empty password must be defined in system.users."
- _pw_users[0].value.password | string | length > 0
fail_msg: "At least one user with a password must be defined in system.users."
quiet: true quiet: true
no_log: true no_log: true