Skip to content

Instantly share code, notes, and snippets.

@Teagan42
Created May 14, 2022 02:03
Show Gist options
  • Save Teagan42/ce3f95e422584fb0ae3e0f84a023f7db to your computer and use it in GitHub Desktop.
Save Teagan42/ce3f95e422584fb0ae3e0f84a023f7db to your computer and use it in GitHub Desktop.
Netplan to NMCLI
{%- set ns = namespace(
ethernets=network_ethernets,
vlans={},
bridges={},
bonds={},
ip={}
)
-%}
{%- for bond_name, bond_config in network_bonds.items() -%}
{%- for interface in bond_config.interfaces -%}
{%- set ns.ethernets =
ns.ethernets
| combine(
{
interface: ns.ethernets[interface] | combine(
{
'controller': bond_name,
'type': 'ethernet',
'interface_name': interface,
'name': interface,
'state': 'up',
'port_type': 'bond'
}
)}) -%}
{%- endfor -%}
{%- endfor -%}
{%- for bridge_name, bridge_config in network_bridges.items() -%}
{%- set ns.ip = {'dhcp4': 'no', 'auto6': 'no'} -%}
{%- if bridge_config.addresses | default(False) -%}
{%- set ns.ip = ns.ip | combine({'address': bridge_config.addresses | first}) -%}
{%- endif -%}
{%- if bridge_config.gateway4 | default(False) -%}
{%- set ns.ip = ns.ip | combine({'auto_gateway': 'yes', 'gateway4': bridge_config.addresses | first}) -%}
{%- endif -%}
{%- if bridge_config.nameservers | default(False) -%}
{%- set ns.ip = ns.ip | combine({'dns': bridge_config.nameservers.addresses, 'dns_search': bridge_config.nameservers.search}) -%}
{%- endif -%}
{%- set ns.bridges =
ns.bridges
| combine(
{
bridge_name:
{
'type': 'ethernet',
'interface_name': bridge_name,
'name': bridge_name,
'state': 'up',
'port_type': 'bridge',
'mtu': bridge_config.mtu | default(1500),
'ip': ns.ip
}
}) -%}
{%- endfor -%}
{{ ns.ethernets.values() | list | to_nice_yaml }}
{{ ns.bridges.values() | list | to_nice_yaml }}
netplan_configuration:
network:
ethernets:
eth0:
mtu: 1500
eth1:
mtu: 1500
bonds:
bond0:
interfaces:
- eth0
- eth1
mtu: 1500
parameters:
down-delay: 0
lacp-rate: fast
mii-monitor-interval: 100
mode: 802.3ad
transmit-hash-policy: layer3+4
up-delay: 0
bridges:
br0:
addresses:
- 10.0.10.100/24
gateway4: 10.0.10.1
interfaces:
- bond0
mtu: 1500
nameservers:
addresses:
- 10.0.10.1
search:
- home.prettybaked.com
parameters:
forward-delay: 0
stp: true
br10:
interfaces:
- bond0.10
mtu: 1500
parameters:
forward-delay: 0
stp: true
br11:
interfaces:
- bond0.11
mtu: 1500
parameters:
forward-delay: 0
stp: true
br12:
interfaces:
- bond0.12
mtu: 1500
parameters:
forward-delay: 0
stp: true
br20:
interfaces:
- bond0.20
mtu: 1500
parameters:
forward-delay: 0
stp: true
br30:
interfaces:
- bond0.30
mtu: 1500
parameters:
forward-delay: 0
stp: true
vlans:
bond0.10:
id: 10
link: bond0
mtu: 1500
bond0.11:
id: 11
link: bond0
mtu: 1500
bond0.12:
id: 12
link: bond0
mtu: 1500
bond0.20:
id: 20
link: bond0
mtu: 1500
bond0.30:
id: 30
link: bond0
mtu: 1500
network_ethernets: '{{ netplan_configuration.network.ethernets }}'
network_bridges: '{{ netplan_configuration.network.bridges }}'
network_bonds: '{{ netplan_configuration.network.bonds }}'
network_vlans: '{{ netplan_configuration.network.vlans }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment