@@ -77,12 +77,50 @@ In both modes, ansible-core evaluated template string results as Python literals
77
77
Selection of the templating mode was controlled by configuration, defaulting to Jinja's original string templating.
78
78
79
79
Starting with this release, use of Jinja's native templating is required.
80
+ The configuration option for setting the templating mode is deprecated and no longer has any effect.
81
+
80
82
Preservation of native types in templating has been improved to correct gaps in the previous implementation,
81
83
entirely eliminating the final literal evaluation pass (a frequent source of confusion, errors, and performance issues).
82
84
In rare cases where playbooks relied on implicit object conversion from strings, an explicit conversion will be
83
85
required.
84
86
85
- The configuration option for setting the templating mode is deprecated and no longer has any effect.
87
+ Some existing templates may unintentionally convert non-strings to strings.
88
+ In previous versions this was sometimes masked by the evaluation of strings as Python literals.
89
+
90
+ Example - Unintentional String Conversion
91
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
92
+
93
+ This expression erroneously passes a list to the ``replace `` filter, which operates only on strings.
94
+ The filter silently converts the list input to a string.
95
+ Due to some string results previously parsing as lists, this mistake often went undetected in earlier versions.
96
+
97
+ .. code-block :: yaml+jinja
98
+
99
+ - debug:
100
+ msg: "{{ ['test1', 'test2'] | replace('test', 'prod') }}"
101
+
102
+ The result of this template becomes a string::
103
+
104
+ ok: [localhost] => {
105
+ "msg": "['prod1', 'prod2']"
106
+ }
107
+
108
+
109
+ This can be resolved by using the ``map `` filter to apply the ``replace `` filter to each list element:
110
+
111
+ .. code-block :: yaml+jinja
112
+
113
+ - debug:
114
+ msg: "{{ ['test1', 'test2'] | map('replace', 'test', 'prod') }}"
115
+
116
+ The result of the corrected template remains a list::
117
+
118
+ ok: [localhost] => {
119
+ "msg": [
120
+ "prod1",
121
+ "prod2"
122
+ ]
123
+ }
86
124
87
125
88
126
Lazy Templating
0 commit comments