diff --git a/changelogs/fragments/ansible_local_nodepr.yml b/changelogs/fragments/ansible_local_nodepr.yml new file mode 100644 index 00000000000..0462c85deed --- /dev/null +++ b/changelogs/fragments/ansible_local_nodepr.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible_local will no longer trigger variable injection default value deprecation. diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index 23fcb5662a2..1067ae45749 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -297,7 +297,7 @@ class VariableManager: # push facts to main namespace if C.INJECT_FACTS_AS_VARS: - deprecated_facts_vars = {k: _deprecate_top_level_fact(v) for k, v in clean_facts(facts).items()} + deprecated_facts_vars = {k: (_deprecate_top_level_fact(v) if k != 'ansible_local' else v) for k, v in clean_facts(facts).items()} all_vars = _combine_and_track(all_vars, deprecated_facts_vars, "facts") else: # always 'promote' ansible_local diff --git a/test/integration/targets/deprecations/injectfacts.yml b/test/integration/targets/deprecations/injectfacts.yml new file mode 100644 index 00000000000..d5110dfe106 --- /dev/null +++ b/test/integration/targets/deprecations/injectfacts.yml @@ -0,0 +1,8 @@ +- hosts: localhost + gather_facts: true + tasks: + - debug: + msg: '{{ansible_distribution}}' + - debug: + msg: '{{ansible_local}}' + tags: alocal diff --git a/test/integration/targets/deprecations/runme.sh b/test/integration/targets/deprecations/runme.sh index c9dc17fdf95..4f8a74f1561 100755 --- a/test/integration/targets/deprecations/runme.sh +++ b/test/integration/targets/deprecations/runme.sh @@ -56,3 +56,9 @@ export ANSIBLE_CACHE_PLUGIN=notjsonfile # check for plugin deprecation [ "$(ansible-doc -t cache notjsonfile --playbook-dir ./ | grep -c 'DEPRECATED:')" -eq "1" ] + +# Injection default is deprecated +[ "$(ANSIBLE_INJECT_FACT_VARS=1 ansible-playbook injectfacts.yml 2>&1 | grep -c 'INJECT_FACTS_AS_VARS')" -eq "0" ] + +# Injection default is deprecated but not ansible_local +[ "$(ansible-playbook injectfacts.yml --tags alocal 2>&1 | grep -c 'INJECT_FACTS_AS_VARS')" -eq "0" ]