Skip to content

Commit c08ed7b

Browse files
patchback[bot]s-herteloraNodfelixfontein
authored
porting guide 2.19 - describe lazy complex var eval impact on builtin filters/tests (#2639) (#2851)
* porting guide 2.19 - describe lazy complex variable evaluation impact for common Jinja2 filters/tests * remove unlikely example * Fix terminology * dnaro suggestion: add comments * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst * Remove 'embedded template' phrasing and remove quotation marks around variable for consistency with other comments --------- (cherry picked from commit 2c0cb48) Co-authored-by: Sloane Hertel <[email protected]> Co-authored-by: Don Naro <[email protected]> Co-authored-by: Felix Fontein <[email protected]>
1 parent 4a4602d commit c08ed7b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,32 @@ Noteworthy plugin changes
782782
This filter now returns ``False`` instead of ``None`` when the input is ``None``.
783783
The aforementioned deprecation warning is also issued in this case.
784784

785+
* Passing nested non-scalars with embedded templates that may resolve to ``Undefined`` to Jinja2
786+
filter plugins, such as ``default`` and ``mandatory``, and test plugins including ``defined`` and ``undefined``
787+
no longer evaluate as they did in previous versions because nested non-scalars with embedded templates are templated
788+
on use only.
789+
In 2.19, this assertion passes:
790+
791+
.. code-block:: yaml
792+
793+
- assert:
794+
that:
795+
# Unlike earlier versions, complex_var is defined even though complex_var.nested is not.
796+
- complex_var is defined
797+
# Unlike earlier versions, the default value is not applied because complex_var is defined.
798+
- (complex_var | default(unused)).nested is undefined
799+
# Like earlier versions, directly accessing complex_var.nested evaluates as undefined.
800+
- complex_var.nested is undefined
801+
vars:
802+
complex_var:
803+
# Before 2.19, complex_var.nested is evaluated immediately when complex_var is accessed.
804+
# In 2.19, complex_var.nested is evaluated only when it is accessed.
805+
nested: "{{ undefined_variable }}"
806+
unused:
807+
# This variable is used only if complex_var is undefined.
808+
# This only happens in ansible-core before 2.19.
809+
nested: default
810+
785811
786812
Porting custom scripts
787813
======================

0 commit comments

Comments
 (0)