From 09fbb2b1d86b8ad6671c746f3df997390f7a6293 Mon Sep 17 00:00:00 2001 From: Ahmed Abdelhalim Date: Mon, 6 Jul 2026 01:49:45 +0200 Subject: Fix pve network setup --- roles/network/meta/argument_specs.yml | 4 +++ roles/network/tasks/main.yml | 9 +++++++ roles/network/templates/bridge.nmconnection.j2 | 29 ++++++++++++++++++++++ .../templates/eth0-connection.nmconnection.j2 | 12 +++++++-- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 roles/network/templates/bridge.nmconnection.j2 (limited to 'roles/network') diff --git a/roles/network/meta/argument_specs.yml b/roles/network/meta/argument_specs.yml index 86df33c6..f85318a8 100644 --- a/roles/network/meta/argument_specs.yml +++ b/roles/network/meta/argument_specs.yml @@ -30,3 +30,7 @@ argument_specs: network_ipv6_dns: type: "str" description: "The network IP(4) gateway to configure when provided" + network_bridge: + type: "str" + description: "Bridge interface name — when set, ethernet becomes bridge port and bridge connection is created" + required: false diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 2cbb2513..1268b3cd 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -103,6 +103,15 @@ owner: "root" group: "root" + - name: "Configure bridge connection" + ansible.builtin.template: + src: "bridge.nmconnection.j2" + dest: "/etc/NetworkManager/system-connections/{{ network_bridge }}.nmconnection" + mode: "0600" + owner: "root" + group: "root" + when: network_bridge is defined + - name: "Configure wifi connection" ansible.builtin.template: src: "wifi-connection.nmconnection.j2" diff --git a/roles/network/templates/bridge.nmconnection.j2 b/roles/network/templates/bridge.nmconnection.j2 new file mode 100644 index 00000000..2e8bf23c --- /dev/null +++ b/roles/network/templates/bridge.nmconnection.j2 @@ -0,0 +1,29 @@ +[connection] +id={{ network_bridge }} +type=bridge +interface-name={{ network_bridge }} +autoconnect=true + +[bridge] +stp=false + +[ipv4] +method=manual +addresses={{ network_ipv4_address }}/{{ network_ipv4_prefix | default(24) }} +gateway={{ network_ipv4_gateway }} +{% if network_ipv4_dns is defined %} +dns={{ network_ipv4_dns }} +{% endif %} + +[ipv6] +addr-gen-mode=default +{% if network_ipv6_address is defined %} +method=manual +addresses={{ network_ipv6_address }} +gateway={{ network_ipv6_gateway }} +{% if network_ipv6_dns is defined %} +dns={{ network_ipv6_dns }} +{% endif %} +{% else %} +method=disabled +{% endif %} diff --git a/roles/network/templates/eth0-connection.nmconnection.j2 b/roles/network/templates/eth0-connection.nmconnection.j2 index 666b0360..6a6481c4 100644 --- a/roles/network/templates/eth0-connection.nmconnection.j2 +++ b/roles/network/templates/eth0-connection.nmconnection.j2 @@ -2,12 +2,18 @@ id=ethernet type=ethernet autoconnect=true +{% if network_bridge is defined %} +controller={{ network_bridge }} +port-type=bridge +{% endif %} [ethernet] cloned-mac-address=permanent [ipv4] -{% if network_ipv4_address is defined %} +{% if network_bridge is defined %} +method=disabled +{% elif network_ipv4_address is defined %} method=manual addresses={{ network_ipv4_address }} gateway={{ network_ipv4_gateway }} @@ -20,7 +26,9 @@ method=auto [ipv6] addr-gen-mode=default -{% if network_ipv6_address is defined %} +{% if network_bridge is defined %} +method=disabled +{% elif network_ipv6_address is defined %} method=manual addresses={{ network_ipv6_address }} gateway={{ network_ipv6_gateway }} -- cgit v1.2.3