diff --git a/changelog/55146.fixed.md b/changelog/55146.fixed.md new file mode 100644 index 000000000000..6ff8a469768c --- /dev/null +++ b/changelog/55146.fixed.md @@ -0,0 +1,2 @@ +Flatten yaml node lists to `L@` or `E@` before trying to do the ext_pillar parsing. +For nested Nodegroups this is already done, but on the first level nodegroup a list will fail parsing as compound match. diff --git a/salt/pillar/nodegroups.py b/salt/pillar/nodegroups.py index 29642c4acf00..4a70c6d5de9e 100644 --- a/salt/pillar/nodegroups.py +++ b/salt/pillar/nodegroups.py @@ -35,7 +35,7 @@ # Import futures -from salt.utils.minions import CkMinions +from salt.utils.minions import CkMinions, nodegroup_comp __version__ = "0.0.2" @@ -56,6 +56,7 @@ def ext_pillar(minion_id, pillar, pillar_name=None): ckminions = None for nodegroup_name in all_nodegroups.keys(): ckminions = ckminions or CkMinions(__opts__) + all_nodegroups[nodegroup_name] = nodegroup_comp(nodegroup_name, all_nodegroups) _res = ckminions.check_minions(all_nodegroups[nodegroup_name], "compound") match = _res["minions"] diff --git a/tests/pytests/unit/pillar/test_nodegroups.py b/tests/pytests/unit/pillar/test_nodegroups.py index 2c4d1bf24311..b4c65ce3208a 100644 --- a/tests/pytests/unit/pillar/test_nodegroups.py +++ b/tests/pytests/unit/pillar/test_nodegroups.py @@ -14,6 +14,7 @@ def fake_nodegroups(fake_minion_id): return { "groupA": fake_minion_id, "groupB": "another_minion_id", + "groupC": [fake_minion_id, "another_minion_id"], } @@ -34,7 +35,9 @@ def configure_loader_modules(fake_minion_id, fake_nodegroups): def _runner(expected_ret, fake_minion_id, fake_pillar_name, pillar_name=None): def _side_effect(group_sel, t): - if group_sel.find(fake_minion_id) != -1: + if not isinstance(group_sel, list): + group_sel = [group_sel] + if any(x for x in group_sel if x.find(fake_minion_id) != -1): return {"minions": [fake_minion_id], "missing": []} return {"minions": ["another_minion_id"], "missing": []} @@ -48,5 +51,5 @@ def _side_effect(group_sel, t): def test_succeeds(fake_pillar_name, fake_minion_id): - ret = {fake_pillar_name: ["groupA"]} + ret = {fake_pillar_name: ["groupA", "groupC"]} _runner(ret, fake_minion_id, fake_pillar_name)