Skip to content

Commit 3c839c0

Browse files
committed
gen_nodes: fix duplicate pcipassthrough keys in YAML output
The template was generating multiple 'pcipassthrough' keys for each device, causing YAML parsing warnings about duplicate mapping keys. Fixed by collecting all devices for a target guest first, then outputting a single 'pcipassthrough' key with all devices under it. This uses Jinja2's namespace feature to maintain state across loop iterations. Generated-by: Claude AI Reviewed-by: Chuck Lever <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent c63ffce commit 3c839c0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

playbooks/roles/gen_nodes/templates/gen_nodes_list.j2

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{%- macro gen_pci_passthrough_each(n, device_list) -%}
2-
{%- set found_pcie_devices_on_node = False -%}
2+
{%- set ns = namespace(has_devices=false, device_index=1) -%}
33
{%- for d in device_list %}
44
{%- if n == d.target_guest -%}
5-
{%- if not found_pcie_devices_on_node -%}
6-
{% set found_pcie_devices_on_node = True %}
5+
{%- if not ns.has_devices -%}
6+
{%- set ns.has_devices = true %}
77
pcipassthrough:
8-
{% endif %}
9-
passthrough{{ loop.index | string }}:
8+
{% endif -%}
9+
passthrough{{ ns.device_index | string }}:
1010
domain: {{ d.domain }}
1111
bus: {{ d.bus }}
1212
slot: {{ d.slot }}
1313
function: {{ d.function }}
14-
{% endif %}
15-
{% endfor -%}
14+
{%- set ns.device_index = ns.device_index + 1 -%}
15+
{%- endif %}
16+
{%- endfor -%}
1617
{%- endmacro -%}
1718
{%- macro gen_pci_passthrough( device_list ) -%}
1819
{%- for d in device_list %}

0 commit comments

Comments
 (0)