mirror of
https://github.com/zebrajr/ansible.git
synced 2025-12-06 00:19:48 +01:00
vars deprecation (#85673)
internal 'vars' dict cache has not been used for long time, but kept since we could not deprecate and some users had found it
This commit is contained in:
parent
931c923e0e
commit
534b8c225a
2
changelogs/fragments/vars_begone.yml
Normal file
2
changelogs/fragments/vars_begone.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
deprecated_features:
|
||||
- vars, the internal variable cache will be removed in 2.24. This cache, once used internally exposes variables in inconsistent states, the 'vars' and 'varnames' lookups should be used instead.
|
||||
|
|
@ -56,6 +56,12 @@ _DEPRECATE_TOP_LEVEL_FACT_TAG = _tags.Deprecated(
|
|||
deprecator=_deprecator.ANSIBLE_CORE_DEPRECATOR,
|
||||
help_text='Use `ansible_facts["fact_name"]` (no `ansible_` prefix) instead.',
|
||||
)
|
||||
_DEPRECATE_VARS = _tags.Deprecated(
|
||||
msg='The internal "vars" dictionary is deprecated.',
|
||||
version='2.24',
|
||||
deprecator=_deprecator.ANSIBLE_CORE_DEPRECATOR,
|
||||
help_text='Use the `vars` and `varnames` lookups instead.',
|
||||
)
|
||||
|
||||
|
||||
def _deprecate_top_level_fact(value: t.Any) -> t.Any:
|
||||
|
|
@ -420,8 +426,10 @@ class VariableManager:
|
|||
|
||||
# 'vars' magic var
|
||||
if task or play:
|
||||
all_vars['vars'] = _DEPRECATE_VARS.tag({})
|
||||
for k, v in all_vars.items():
|
||||
# has to be copy, otherwise recursive ref
|
||||
all_vars['vars'] = all_vars.copy()
|
||||
all_vars['vars'][k] = _DEPRECATE_VARS.tag(v)
|
||||
|
||||
display.debug("done with get_vars()")
|
||||
return all_vars
|
||||
|
|
|
|||
|
|
@ -13,3 +13,6 @@ ansible-playbook task_vars_templating.yml -v "$@"
|
|||
|
||||
# there should be an attempt to use 'sudo' in the connection debug output
|
||||
ANSIBLE_BECOME_ALLOW_SAME_USER=true ansible-playbook test_connection_vars.yml -vvvv "$@" | tee /dev/stderr | grep 'sudo \-H \-S'
|
||||
|
||||
# test vars deprecation
|
||||
ANSIBLE_DEPRECATION_WARNINGS=1 ansible-playbook vars_deprecation.yml "$@"
|
||||
|
|
|
|||
16
test/integration/targets/var_templating/vars_deprecation.yml
Normal file
16
test/integration/targets/var_templating/vars_deprecation.yml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
- hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
deprecation_message: 'The internal "vars" dictionary is deprecated'
|
||||
tasks:
|
||||
- shell: !unsafe ansible -m debug -a "msg='{{vars}}'" localhost
|
||||
register: just_vars
|
||||
|
||||
- shell: !unsafe ansible -m debug -a 'msg="{{vars["'"ansible_python_interpreter"'"]}}"' localhost
|
||||
register: sub_vars
|
||||
|
||||
- name: verify we got deprecation
|
||||
assert:
|
||||
that:
|
||||
- deprecation_message in just_vars.stderr
|
||||
- deprecation_message in sub_vars.stderr
|
||||
Loading…
Reference in New Issue
Block a user