mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-13 04:34:24 +00:00
Refactor task includes and update variable handling for Ansible 2.20 migration
This commit updates multiple roles to ensure compatibility with Ansible 2.20. Several include paths and task-loading mechanisms required adjustments, as Ansible 2.20 applies stricter evaluation rules for complex Jinja expressions and no longer resolves certain relative include paths the way Ansible 2.18 did. Key changes: - Replaced legacy once_finalize.yml and once_flag.yml with the new structure under tasks/utils/once/finalize.yml and tasks/utils/once/flag.yml. - Updated all include_tasks statements to use 'path_join' with playbook_dir, ensuring deterministic and absolute file resolution across roles. - Fixed all network helper includes by converting direct relative paths such as 'roles/docker-compose/tasks/utils/network.yml' to proper Jinja-evaluated paths. - Normalized MATOMO_* variable names for consistency with the updated variable scope behavior in Ansible 2.20. - Removed deprecated patterns that were implicitly supported in Ansible 2.18 but break under the more strict variable and path resolution model in 2.20. These changes are part of the full migration step required to ensure the infinito-nexus roles remain stable, deterministic, and forward-compatible with Ansible 2.20. Details of the discussion and reasoning can be found in this conversation: https://chatgpt.com/share/69300a8d-24d4-800f-bec0-e895a695618a
This commit is contained in:
@@ -10,7 +10,7 @@ What it enforces:
|
||||
- That exact suffix must be defined EITHER
|
||||
A) globally via any `set_fact:` assigning `run_once_<suffix>: ...`, OR
|
||||
B) inside that role's tasks:
|
||||
- include_tasks|import_tasks: utils/once_finalize.yml (any style), OR
|
||||
- include_tasks|import_tasks: utils/once/finalize.yml (any style), OR
|
||||
- set_fact: { run_once_<suffix>: ... }
|
||||
* If <suffix> does NOT match any role (an unknown suffix):
|
||||
- It MUST be defined globally via `set_fact` somewhere in a valid YAML file.
|
||||
@@ -45,8 +45,8 @@ RUN_ONCE_USAGE_RE = re.compile(r'\brun_once_([A-Za-z0-9_]+)\b')
|
||||
|
||||
# Task files that "define" a run-once flag for a role
|
||||
RUN_ONCE_TASK_FILES = (
|
||||
'utils/once_finalize.yml',
|
||||
'utils/once_flag.yml',
|
||||
'utils/once/finalize.yml',
|
||||
'utils/once/flag.yml',
|
||||
)
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ def file_role_by_prefix(path: str, role_tasks_roots: dict[str, str]) -> str | No
|
||||
def role_defines_suffix_in_doc(doc, role_suffix: str) -> bool:
|
||||
"""
|
||||
Return True if this YAML doc (already parsed) defines run-once for the given role suffix via:
|
||||
A) include/import utils/once_finalize.yml or utils/once_flag.yml (string or mapping style), OR
|
||||
A) include/import utils/once/finalize.yml or utils/once/flag.yml (string or mapping style), OR
|
||||
B) set_fact: { run_once_<role_suffix>: ... }
|
||||
"""
|
||||
if doc is None:
|
||||
@@ -156,7 +156,7 @@ def role_defines_suffix_in_doc(doc, role_suffix: str) -> bool:
|
||||
while queue:
|
||||
node = queue.pop()
|
||||
if isinstance(node, dict):
|
||||
# A) include/import utils/once_finalize.yml or utils/once_flag.yml
|
||||
# A) include/import utils/once/finalize.yml or utils/once/flag.yml
|
||||
for key in ('include_tasks', 'import_tasks'):
|
||||
if key in node:
|
||||
val = node[key]
|
||||
@@ -241,7 +241,7 @@ class RunOnceGlobalUsageFastTest(unittest.TestCase):
|
||||
role = file_role_by_prefix(yml, role_tasks_roots)
|
||||
if role:
|
||||
role_suffix = suffix_for_role[role]
|
||||
# utils/once_finalize.yml inside role tasks defines that role's own suffix
|
||||
# utils/once/finalize.yml inside role tasks defines that role's own suffix
|
||||
# OR a direct set_fact with exact run_once_<role_suffix>
|
||||
for doc in docs:
|
||||
if role_defines_suffix_in_doc(doc, role_suffix):
|
||||
@@ -276,7 +276,7 @@ class RunOnceGlobalUsageFastTest(unittest.TestCase):
|
||||
"Some run_once_<suffix> usages in valid YAML files are missing exact definitions.",
|
||||
"Rules:",
|
||||
" • Unknown suffixes must be defined globally via set_fact.",
|
||||
" • Known role suffixes must be defined globally OR in that role (include/import utils/once_finalize.yml or set_fact).",
|
||||
" • Known role suffixes must be defined globally OR in that role (include/import utils/once/finalize.yml or set_fact).",
|
||||
"",
|
||||
"Offenders:"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user