From 34052a2de8ed7ebfa5f19bc19ed8e0e212a36a29 Mon Sep 17 00:00:00 2001 From: Fiehe Christoph Date: Wed, 4 Mar 2026 23:40:38 +0100 Subject: [PATCH] Specification of transformations solely as string Signed-off-by: Fiehe Christoph --- plugins/lookup/merge_variables.py | 30 ++++--------------- .../plugins/lookup/test_merge_variables.py | 2 +- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/plugins/lookup/merge_variables.py b/plugins/lookup/merge_variables.py index a175811dab..d59fdc5afa 100644 --- a/plugins/lookup/merge_variables.py +++ b/plugins/lookup/merge_variables.py @@ -115,22 +115,11 @@ options: list_transformations: description: - List transformations applied to list types. The definition order corresponds to the order in which these transformations are applied. - - Elements can be a dict with the keys mentioned below or a string naming the transformation to apply. type: list - elements: raw - suboptions: - name: - description: - - Name of the list transformation. - required: true - type: str - choices: - flatten: Flatten lists, converting nested lists into single lists. - dedup: Remove duplicates from lists. - options: - description: - - Options as key value pairs. V(flatten) and V(dedup) do not support any additional options. - type: dict + elements: str + choices: + - flatten + - dedup default: [] version_added: 12.5.0 """ @@ -356,16 +345,7 @@ class LookupModule(LookupBase): builder.with_type_strategy(dict, DictMergeStrategies.from_name(self._dict_merge)) for transformation in self._list_transformations: - if isinstance(transformation, str): - builder.with_transformation(list, ListTransformations.from_name(transformation)) - elif isinstance(transformation, dict): - name = transformation["name"] - options = transformation.get("options", {}) - builder.with_transformation(list, ListTransformations.from_name(name, **options)) - else: - raise AnsibleError( - f"Transformations must be specified through values of type 'str' or 'dict', but a value of type '{type(transformation)}' was given." - ) + builder.with_transformation(list, ListTransformations.from_name(transformation)) merger = builder.build() diff --git a/tests/unit/plugins/lookup/test_merge_variables.py b/tests/unit/plugins/lookup/test_merge_variables.py index ae6c14592d..1305d05210 100644 --- a/tests/unit/plugins/lookup/test_merge_variables.py +++ b/tests/unit/plugins/lookup/test_merge_variables.py @@ -732,7 +732,7 @@ class TestMergeVariablesLookup(unittest.TestCase): @patch.object( AnsiblePlugin, "get_option", - side_effect=[None, "ignore", "suffix", None, "deep", "append", "replace", "replace", [{"name": "dedup"}]], + side_effect=[None, "ignore", "suffix", None, "deep", "append", "replace", "replace", ["dedup"]], ) @patch.object( Templar, "template", side_effect=[deepcopy(merge_hash_data["low_prio"]), deepcopy(merge_hash_data["high_prio"])]