Skip to content

Use boolean jinja2 template overrides - #710

Open
GeertJohan wants to merge 1 commit into
metal-stack:masterfrom
GeertJohan:fix/jinja2-template-overrides
Open

Use boolean jinja2 template overrides#710
GeertJohan wants to merge 1 commit into
metal-stack:masterfrom
GeertJohan:fix/jinja2-template-overrides

Conversation

@GeertJohan

Copy link
Copy Markdown
Contributor

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

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
GeertJohan requested a review from a team as a code owner August 4, 2026 14:43
@GeertJohan
GeertJohan requested a review from iljarotar August 4, 2026 14:43
@metal-robot metal-robot Bot added the area: deployment Affects the deployment area. label Aug 4, 2026
@metal-robot metal-robot Bot added this to Development Aug 4, 2026
@@ -1,4 +1,4 @@
#jinja2: lstrip_blocks: "False", trim_blocks: "False"
#jinja2: lstrip_blocks: True, trim_blocks: True

@GeertJohan GeertJohan Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this change keeps behavior unchanged, but perhaps we want to change the behavior to actually lstrip and trim?

@GeertJohan GeertJohan changed the title use boolean jinja2 template overrides Use boolean jinja2 template overrides Aug 4, 2026
@iljarotar iljarotar moved this to In Progress in Development Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: deployment Affects the deployment area.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants