You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/template
Martin Krizek 89e6dcda26
Prevent losing unsafe from lookups (#77609) (#77650)
* Prevent losing unsafe from lookups

This patch fixes a bug which under certain conditions results in data
returned from lookups not being marked as unsafe.

Each time Templar.do_template is invoked a new AnsibleContext is
created and stored effectively at two places:
1) as an instance variable in templar_obj.cur_context
2) as a local variable called new_context in do_template method of Templar

Due to custom functionality in Ansible's Context that allows for nested
templating it is possible that during resolving variable's value
template/do_template method is called recursively again, again creating
a new context. At that point the problem manifests itself because as
mentioned in 1) above the context is overwriten on the templar object
which means that any subsequent calls to _lookup will use the new
context to mark it as unsafe which is now different to the local
new_context which is used for testing for unsafe property.

The solution to the problem appears to be to restore the original
context inside do_template and also to eliminate the local variable
new_context to prevent problems in the future.

It appears that we don't have a better way of storing the context other
than as some form of global variable and so this appears to be the
"best" solution possible at this point. Hopefully data tagging will be
the solution here.

For more examples see unit and integration tests included in this patch.

Fixes #77535

(cherry picked from commit 3980eb8c09)
4 years ago
..
custom_tasks Clean up various integration tests. (#60613) 6 years ago
files Heisen jinja2_native (#75587) 4 years ago
meta test - add setup target that creates the nobody user (#52750) 7 years ago
role_filter More boilerplate fixes. (#70224) 6 years ago
tasks Remove unused task from template integration test. 4 years ago
templates ansible_concat: return strings only unless eval (#76634) 4 years ago
vars
6653.yml Local vars should have highest precedence in AnsibleJ2Vars (#72830) 5 years ago
72262.yml Local vars should have highest precedence in AnsibleJ2Vars (#72830) 5 years ago
72615.yml Require Jinja2 3.0.0 (#75881) 4 years ago
aliases ansible-test - split controller/target testing (#75605) 4 years ago
ansible_managed.cfg Fix when template paths contain non-ascii chars and using the path in ansible_managed 8 years ago
ansible_managed.yml Clean up various integration tests. (#60613) 6 years ago
corner_cases.yml Heisen jinja2_native (#75587) 4 years ago
custom_template.yml dataloader: check exact value of dir (#52021) 7 years ago
filter_plugins.yml Revert "Speed up VariableManager by preserving Templar state. (#45572)" (#59280) 7 years ago
in_template_overrides.j2 Ensure Jinja2 template header overrides are used (#75306) 4 years ago
in_template_overrides.yml Ensure Jinja2 template header overrides are used (#75306) 4 years ago
runme.sh Add an `undef` global Jinja function (#75435) 4 years ago
template.yml
undefined_var_info.yml Provide more information in AnsibleUndefinedVariable (#71666) 5 years ago
unsafe.yml Prevent losing unsafe from lookups (#77609) (#77650) 4 years ago
unused_vars_include.yml Prevent templating unused variables for {%include%} (#68749) 6 years ago