From 51bf8ed298f5e00d372b170785a5864b79ff4153 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 25 Feb 2023 15:39:43 +0100 Subject: [PATCH] [PR #6074/b6492911 backport][stable-5] stop passing loader/dataloader since it has been deprecated by ansible (#6091) 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 (cherry picked from commit b64929118ebf276169bd26c81e650579b3c3d207) Co-authored-by: schurzi --- 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 516d153389..bdc8973920 100644 --- a/plugins/lookup/cartesian.py +++ b/plugins/lookup/cartesian.py @@ -64,7 +64,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 25098fa23a..dda48a21b1 100644 --- a/plugins/lookup/flattened.py +++ b/plugins/lookup/flattened.py @@ -64,7 +64,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