From dbdb4bd17b4960c8e8fe4ec3ce56008df983998c Mon Sep 17 00:00:00 2001 From: Bert Coleman Date: Tue, 26 Aug 2025 15:01:14 -0600 Subject: [PATCH] initial commit --- changelog/31427.fixed.md | 1 + salt/modules/grains.py | 4 ++++ tests/integration/files/conf/minion | 6 ++++++ .../integration/modules/grains/test_module.py | 12 ++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 changelog/31427.fixed.md diff --git a/changelog/31427.fixed.md b/changelog/31427.fixed.md new file mode 100644 index 000000000000..5cc5462e3817 --- /dev/null +++ b/changelog/31427.fixed.md @@ -0,0 +1 @@ +Fixes duplicate roles returning in list from grains.item call diff --git a/salt/modules/grains.py b/salt/modules/grains.py index c9f9d1481d53..b9a162ebafd8 100644 --- a/salt/modules/grains.py +++ b/salt/modules/grains.py @@ -206,6 +206,10 @@ def item(*args, **kwargs): for arg, func in _SANITIZERS.items(): if arg in ret: ret[arg] = func(ret[arg]) + + if isinstance(ret[arg], list): + unique_ret = list(dict.fromkeys(ret[arg])) + ret[arg] = unique_ret return ret diff --git a/tests/integration/files/conf/minion b/tests/integration/files/conf/minion index 06992fb8c035..00edd2bac343 100644 --- a/tests/integration/files/conf/minion +++ b/tests/integration/files/conf/minion @@ -24,6 +24,12 @@ integration.test: True # Grains addons grains: + roles: + - one + - two + - three + - three + - four test_grain: cheese script: grail alot: many diff --git a/tests/pytests/integration/modules/grains/test_module.py b/tests/pytests/integration/modules/grains/test_module.py index bb977af91833..f833ae4e5985 100644 --- a/tests/pytests/integration/modules/grains/test_module.py +++ b/tests/pytests/integration/modules/grains/test_module.py @@ -42,6 +42,18 @@ def test_item(salt_call_cli, minion_test_grain): assert ret.data["test_grain"] == minion_test_grain +def test_item_no_duplicate(salt_call_cli): + """ + grains.item + """ + expected = ["one", "two", "three", "four"] + ret = salt_call_cli.run("grains.item", "roles") + assert ret.returncode == 0 + assert ret.data + assert isinstance(ret.data, dict) + assert ret.data["roles"] == expected + + def test_ls(salt_call_cli, grains): """ grains.ls