From e9a8a448dd7e6d431a26f603bf111a3eefa503ef Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 14 Jan 2026 17:16:47 -0500 Subject: [PATCH] ansible_local should not trigger deprecation (#86234) (#86302) * ansible_local should not trigger deprecation fixes #86228 (cherry picked from commit ca6dc93dcc626add955777b9fa5540670c9b40c6) --- changelogs/fragments/ansible_local_nodepr.yml | 2 ++ lib/ansible/vars/manager.py | 2 +- test/integration/targets/deprecations/injectfacts.yml | 8 ++++++++ test/integration/targets/deprecations/runme.sh | 6 ++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible_local_nodepr.yml create mode 100644 test/integration/targets/deprecations/injectfacts.yml 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" ]