From b64929118ebf276169bd26c81e650579b3c3d207 Mon Sep 17 00:00:00 2001 From: schurzi Date: Sat, 25 Feb 2023 15:29:27 +0100 Subject: [PATCH] stop passing loader/dataloader since it has been deprecated by ansible (#6074) * stop passing loader/dataloader since it has been deprecated by ansible Signed-off-by: Martin Schurz * add changelog fragment Signed-off-by: Martin Schurz * explicitly pass None to keep compatibility to older Ansible versions Signed-off-by: Martin Schurz * use try/except to keep things compatible Signed-off-by: Martin Schurz * Update plugins/lookup/cartesian.py Co-authored-by: Felix Fontein * Update plugins/lookup/flattened.py Co-authored-by: Felix Fontein * Update plugins/lookup/flattened.py Co-authored-by: Felix Fontein * Update plugins/lookup/cartesian.py Co-authored-by: Felix Fontein * Update changelogs/fragments/6074-loader_in_listify.yml.yml Co-authored-by: Felix Fontein --------- Signed-off-by: Martin Schurz Co-authored-by: Felix Fontein --- changelogs/fragments/6074-loader_in_listify.yml.yml | 2 ++ plugins/lookup/cartesian.py | 7 ++++++- plugins/lookup/flattened.py | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/6074-loader_in_listify.yml.yml diff --git a/changelogs/fragments/6074-loader_in_listify.yml.yml b/changelogs/fragments/6074-loader_in_listify.yml.yml new file mode 100644 index 0000000000..3c01cde754 --- /dev/null +++ b/changelogs/fragments/6074-loader_in_listify.yml.yml @@ -0,0 +1,2 @@ +minor_changes: + - cartesian and flattened lookup plugins - adjust to parameter deprecation in ansible-core 2.14's ``listify_lookup_plugin_terms`` helper function (https://github.com/ansible-collections/community.general/pull/6074). diff --git a/plugins/lookup/cartesian.py b/plugins/lookup/cartesian.py index d76e8f532a..d63f3943b0 100644 --- a/plugins/lookup/cartesian.py +++ b/plugins/lookup/cartesian.py @@ -66,7 +66,12 @@ class LookupModule(LookupBase): """ results = [] for x in terms: - intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader) + try: + intermediate = listify_lookup_plugin_terms(x, templar=self._templar) + except TypeError: + # The loader argument is deprecated in ansible-core 2.14+. Fall back to + # pre-2.14 behavior for older ansible-core versions. + intermediate = listify_lookup_plugin_terms(x, templar=self._templar, loader=self._loader) results.append(intermediate) return results diff --git a/plugins/lookup/flattened.py b/plugins/lookup/flattened.py index 0f290e559d..e955b6478e 100644 --- a/plugins/lookup/flattened.py +++ b/plugins/lookup/flattened.py @@ -67,7 +67,12 @@ class LookupModule(LookupBase): if isinstance(term, string_types): # convert a variable to a list - term2 = listify_lookup_plugin_terms(term, templar=self._templar, loader=self._loader) + try: + term2 = listify_lookup_plugin_terms(term, templar=self._templar) + except TypeError: + # The loader argument is deprecated in ansible-core 2.14+. Fall back to + # pre-2.14 behavior for older ansible-core versions. + term2 = listify_lookup_plugin_terms(term, templar=self._templar, loader=self._loader) # but avoid converting a plain string to a list of one string if term2 != [term]: term = term2