Use boolean jinja2 template overrides - #710
Open
GeertJohan wants to merge 1 commit into
Open
Conversation
ansible-core 2.19 and later reject non-boolean values in the jinja2 override header, so quoted values like "True" fail with 'TemplateOverrides.trim_blocks must be <class bool>'. On older ansible versions the header value is parsed with ast.literal_eval and the quotes are part of the header text, so "False" yields the string 'False' rather than the boolean. Jinja2 later uses that value in a boolean context, where a non-empty string counts as enabled, which means the metal.yaml.j2 header effectively behaved as True. The headers are therefore set to the literal booleans that match the current rendering behavior, verified against the existing template golden tests.
GeertJohan
commented
Aug 4, 2026
| @@ -1,4 +1,4 @@ | |||
| #jinja2: lstrip_blocks: "False", trim_blocks: "False" | |||
| #jinja2: lstrip_blocks: True, trim_blocks: True | |||
Contributor
Author
There was a problem hiding this comment.
So this change keeps behavior unchanged, but perhaps we want to change the behavior to actually lstrip and trim?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ansible-core 2.19 and later reject non-boolean values in the jinja2 override header, so quoted values like "True" fail with 'TemplateOverrides.trim_blocks must be '.
On older ansible versions the header value is parsed with ast.literal_eval and the quotes are part of the header text, so "False" yields the string 'False' rather than the boolean. Jinja2 later uses that value in a boolean context, where a non-empty string counts as enabled, which means the metal.yaml.j2 header effectively behaved as True. The headers are therefore set to the literal booleans that match the current rendering behavior, verified against the existing template golden tests.
Used AI-Tools ✨
Claude Fable 5