From 1f59bbf4f39504c8f2087f8132f2475a6ac38dcb Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 12 Jul 2022 16:10:32 -0400 Subject: [PATCH] listify_lookup_plugin_terms deprecate dataloader (#78244) * listify_lookup_plugin_terms deprecate dataloader deprecated useless dataloader pass to function also removed from callers in core Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> --- changelogs/fragments/loader_in_listify.yml | 4 ++++ lib/ansible/executor/task_executor.py | 3 +-- lib/ansible/plugins/lookup/nested.py | 2 +- lib/ansible/plugins/lookup/subelements.py | 2 +- lib/ansible/plugins/lookup/together.py | 2 +- lib/ansible/template/__init__.py | 2 +- lib/ansible/utils/listify.py | 8 +++++++- lib/ansible/vars/manager.py | 3 +-- 8 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/loader_in_listify.yml diff --git a/changelogs/fragments/loader_in_listify.yml b/changelogs/fragments/loader_in_listify.yml new file mode 100644 index 00000000000..fd8cad36c55 --- /dev/null +++ b/changelogs/fragments/loader_in_listify.yml @@ -0,0 +1,4 @@ +deprecated_features: + - listify_lookup_plugin_terms, deprecate 'loader/dataloader' parameter as it not used. +minor_changes: + - calls to listify_lookup_plugin_terms in core do not pass in loader/dataloader anymore. diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 47b3ad323ef..571f46b4c3d 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -226,8 +226,7 @@ class TaskExecutor: # first_found loops are special. If the item is undefined then we want to fall through to the next value rather than failing. fail = False - loop_terms = listify_lookup_plugin_terms(terms=self._task.loop, templar=templar, loader=self._loader, fail_on_undefined=fail, - convert_bare=False) + loop_terms = listify_lookup_plugin_terms(terms=self._task.loop, templar=templar, fail_on_undefined=fail, convert_bare=False) if not fail: loop_terms = [t for t in loop_terms if not templar.is_template(t)] diff --git a/lib/ansible/plugins/lookup/nested.py b/lib/ansible/plugins/lookup/nested.py index c2a2b68fb9e..e768dbadd17 100644 --- a/lib/ansible/plugins/lookup/nested.py +++ b/lib/ansible/plugins/lookup/nested.py @@ -60,7 +60,7 @@ class LookupModule(LookupBase): results = [] for x in terms: try: - intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader, fail_on_undefined=True) + intermediate = listify_lookup_plugin_terms(x, templar=self._templar, fail_on_undefined=True) except UndefinedError as e: raise AnsibleUndefinedVariable("One of the nested variables was undefined. The error was: %s" % e) results.append(intermediate) diff --git a/lib/ansible/plugins/lookup/subelements.py b/lib/ansible/plugins/lookup/subelements.py index 2250d579909..9b1af8b4e19 100644 --- a/lib/ansible/plugins/lookup/subelements.py +++ b/lib/ansible/plugins/lookup/subelements.py @@ -101,7 +101,7 @@ class LookupModule(LookupBase): raise AnsibleError( "subelements lookup expects a list of two or three items, " + msg) - terms[0] = listify_lookup_plugin_terms(terms[0], templar=self._templar, loader=self._loader) + terms[0] = listify_lookup_plugin_terms(terms[0], templar=self._templar) # check lookup terms - check number of terms if not isinstance(terms, list) or not 2 <= len(terms) <= 3: diff --git a/lib/ansible/plugins/lookup/together.py b/lib/ansible/plugins/lookup/together.py index 0d2aa4d816d..c990e06ba9e 100644 --- a/lib/ansible/plugins/lookup/together.py +++ b/lib/ansible/plugins/lookup/together.py @@ -53,7 +53,7 @@ class LookupModule(LookupBase): def _lookup_variables(self, terms): results = [] for x in terms: - intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader) + intermediate = listify_lookup_plugin_terms(x, templar=self._templar) results.append(intermediate) return results diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index 1809a696177..1c0bb8eac4f 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -978,7 +978,7 @@ class Templar: allow_unsafe = kwargs.pop('allow_unsafe', C.DEFAULT_ALLOW_UNSAFE_LOOKUPS) errors = kwargs.pop('errors', 'strict') - loop_terms = listify_lookup_plugin_terms(terms=args, templar=self, loader=self._loader, fail_on_undefined=True, convert_bare=False) + loop_terms = listify_lookup_plugin_terms(terms=args, templar=self, fail_on_undefined=True, convert_bare=False) # safely catch run failures per #5059 try: ran = instance.run(loop_terms, variables=self._available_variables, **kwargs) diff --git a/lib/ansible/utils/listify.py b/lib/ansible/utils/listify.py index 4f2ae9d446d..0e6a8724911 100644 --- a/lib/ansible/utils/listify.py +++ b/lib/ansible/utils/listify.py @@ -22,12 +22,18 @@ __metaclass__ = type from collections.abc import Iterable from ansible.module_utils.six import string_types +from ansible.utils.display import Display +display = Display() __all__ = ['listify_lookup_plugin_terms'] -def listify_lookup_plugin_terms(terms, templar, loader, fail_on_undefined=True, convert_bare=False): +def listify_lookup_plugin_terms(terms, templar, loader=None, fail_on_undefined=True, convert_bare=False): + + if loader is not None: + display.deprecated('"listify_lookup_plugin_terms" does not use "dataloader" anymore, the ability to pass it in will be removed in future versions.', + version='2.18') if isinstance(terms, string_types): terms = templar.template(terms.strip(), convert_bare=convert_bare, fail_on_undefined=fail_on_undefined) diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index 9ca30daf675..93538f70df9 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -550,8 +550,7 @@ class VariableManager: # first_found loops are special. If the item is undefined then we want to fall through to the next fail = False try: - loop_terms = listify_lookup_plugin_terms(terms=task.loop, templar=templar, - loader=self._loader, fail_on_undefined=fail, convert_bare=False) + loop_terms = listify_lookup_plugin_terms(terms=task.loop, templar=templar, fail_on_undefined=fail, convert_bare=False) if not fail: loop_terms = [t for t in loop_terms if not templar.is_template(t)]