From ff5deaf62fa7c4fd610fb77c80d02ca8311e8f33 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:45:25 -0400 Subject: [PATCH] fix module_defaults group incorrectly giving deprecation warnings (#83510) don't display deprecation warnings for actions/modules as a result of using an action_group containing a deprecated plugin --- changelogs/fragments/fix-module-defaults-deprecations.yml | 2 ++ lib/ansible/playbook/base.py | 6 +++--- .../ansible_collections/testns/testcoll/meta/runtime.yml | 7 +++++++ test/integration/targets/module_defaults/runme.sh | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/fix-module-defaults-deprecations.yml diff --git a/changelogs/fragments/fix-module-defaults-deprecations.yml b/changelogs/fragments/fix-module-defaults-deprecations.yml new file mode 100644 index 00000000000..e0242aae3ca --- /dev/null +++ b/changelogs/fragments/fix-module-defaults-deprecations.yml @@ -0,0 +1,2 @@ +bugfixes: + - module_defaults - do not display action/module deprecation warnings when using an action_group that contains a deprecated plugin (https://github.com/ansible/ansible/issues/83490). diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index b046f408cec..552dfbb1400 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -386,13 +386,13 @@ class FieldAttributeBase: return fq_group_name, resolved_actions def _resolve_action(self, action_name, mandatory=True): - context = module_loader.find_plugin_with_context(action_name) + context = module_loader.find_plugin_with_context(action_name, ignore_deprecated=(not mandatory)) if context.resolved and not context.action_plugin: - prefer = action_loader.find_plugin_with_context(action_name) + prefer = action_loader.find_plugin_with_context(action_name, ignore_deprecated=(not mandatory)) if prefer.resolved: context = prefer elif not context.resolved: - context = action_loader.find_plugin_with_context(action_name) + context = action_loader.find_plugin_with_context(action_name, ignore_deprecated=(not mandatory)) if context.resolved: return context.resolved_fqcn diff --git a/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml b/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml index 145941caadd..5968c6f620a 100644 --- a/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml +++ b/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml @@ -44,12 +44,19 @@ plugin_routing: ios_facts: action_plugin: testns.testcoll.redirected_action + old_ping: + deprecation: + removal_date: 2020-12-31 + warning_text: old_ping will be removed in a future release of this collection. Use ping instead. + redirect: ping + action_groups: testgroup: # Test metadata 'extend_group' feature does not get stuck in a recursive loop - metadata: extend_group: othergroup - metadata + - old_ping - ping - testns.testcoll.echo1 - testns.testcoll.echo2 diff --git a/test/integration/targets/module_defaults/runme.sh b/test/integration/targets/module_defaults/runme.sh index fe9c40ce627..afb68f1b9b6 100755 --- a/test/integration/targets/module_defaults/runme.sh +++ b/test/integration/targets/module_defaults/runme.sh @@ -5,7 +5,8 @@ set -eux # Symlink is test for backwards-compat (only workaround for https://github.com/ansible/ansible/issues/77059) sudo ln -s "${PWD}/collections/ansible_collections/testns/testcoll/plugins/action/vyos.py" ./collections/ansible_collections/testns/testcoll/plugins/action/vyosfacts.py -ansible-playbook test_defaults.yml "$@" +ANSIBLE_DEPRECATION_WARNINGS=true ansible-playbook test_defaults.yml "$@" 2> err.txt +test "$(grep -c 'testns.testcoll.old_ping has been deprecated' err.txt || 0)" -eq 0 sudo rm ./collections/ansible_collections/testns/testcoll/plugins/action/vyosfacts.py