From 2ac6c0878d31844df9bfce3a8e965fdf53bf7245 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 21 Jul 2026 12:04:53 +0200 Subject: [PATCH] fix(yaml): tolerate ansible-vault tags in the shared loader The cached YAML loader crashed on the !vault tag with a ConstructorError, so any lint test that walks the tree and parses every .yml (yaml-syntax, role/group-vars usage, ...) failed as soon as a vault-encrypted inventory was present. Register a !vault constructor on SafeLoader that loads the ciphertext as a plain scalar, mirroring the existing !override/!reset handling. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/lint/filesystem/test_yaml_syntax.py | 5 +---- utils/cache/yaml.py | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/lint/filesystem/test_yaml_syntax.py b/tests/lint/filesystem/test_yaml_syntax.py index c863e6626e..d3df4afdc9 100644 --- a/tests/lint/filesystem/test_yaml_syntax.py +++ b/tests/lint/filesystem/test_yaml_syntax.py @@ -23,10 +23,7 @@ class TestYamlSyntax(unittest.TestCase): invalid.append((full, f"Unexpected error: {e}")) if invalid: - msg_lines = [ - f"{path}: {err.splitlines()[0]}" # just the first line of the error - for path, err in invalid - ] + msg_lines = [f"{path}: {err.splitlines()[0]}" for path, err in invalid] self.fail( "Found invalid YAML in the following files:\n" + "\n".join(msg_lines) ) diff --git a/utils/cache/yaml.py b/utils/cache/yaml.py index 42d300e890..c801ba4bfe 100644 --- a/utils/cache/yaml.py +++ b/utils/cache/yaml.py @@ -50,6 +50,13 @@ def _construct_compose_merge_tag(loader, node): for _tag in ("!override", "!reset"): yaml.SafeLoader.add_constructor(_tag, _construct_compose_merge_tag) + +def _construct_vault_tag(loader, node): + return loader.construct_scalar(node) + + +yaml.SafeLoader.add_constructor("!vault", _construct_vault_tag) + _MISSING = object() _CACHE: dict[tuple[str, int, int], list[Any]] = {}