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
pull/85723/head
Brian Coca 3 months ago committed by GitHub
parent 931c923e0e
commit 534b8c225a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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, deprecator=_deprecator.ANSIBLE_CORE_DEPRECATOR,
help_text='Use `ansible_facts["fact_name"]` (no `ansible_` prefix) instead.', 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: def _deprecate_top_level_fact(value: t.Any) -> t.Any:
@ -420,8 +426,10 @@ class VariableManager:
# 'vars' magic var # 'vars' magic var
if task or play: if task or play:
# has to be copy, otherwise recursive ref all_vars['vars'] = _DEPRECATE_VARS.tag({})
all_vars['vars'] = all_vars.copy() for k, v in all_vars.items():
# has to be copy, otherwise recursive ref
all_vars['vars'][k] = _DEPRECATE_VARS.tag(v)
display.debug("done with get_vars()") display.debug("done with get_vars()")
return all_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 # 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' 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 "$@"

@ -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…
Cancel
Save