a2af8432f3
Ability to add local variables into AnsibleJ2Vars was added in
18a9eff11f
to fix #6653. Local variables
are added using ``AnsibleJ2Vars.add_locals()`` method when creating a
new context - typically when including/importing a template with
context. For that use case local template variables created using
``set`` should override variables from higher contexts - either from the
play or any parent template, or both; Jinja behaves the same way.
Also removes AnsibleJ2Vars.extras instance variable which is not used.
Also adds missing test for #6653.
Fixes #72262
Fixes #72615
ci_complete
26 lines
961 B
YAML
26 lines
961 B
YAML
- hosts: localhost
|
|
gather_facts: no
|
|
vars:
|
|
foo: "top-level-foo"
|
|
tasks:
|
|
- set_fact:
|
|
template_result: "{{ lookup('template', '72615.j2') }}"
|
|
|
|
- assert:
|
|
that:
|
|
- "'template-level-bar' in template_result"
|
|
- "'template-nested-level-bar' in template_result"
|
|
|
|
- assert:
|
|
that:
|
|
- "'top-level-foo' not in template_result"
|
|
- "'template-level-foo' in template_result"
|
|
- "'template-nested-level-foo' in template_result"
|
|
when: lookup('pipe', ansible_python_interpreter ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.9', '>=')
|
|
|
|
- assert:
|
|
that:
|
|
- "'top-level-foo' in template_result"
|
|
- "'template-level-foo' not in template_result"
|
|
- "'template-nested-level-foo' not in template_result"
|
|
when: lookup('pipe', ansible_python_interpreter ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.9', '<')
|