-if node[:networking][:engine] == "netplan"
- package "netplan.io"
-
- netplan = {
- "network" => {
- "version" => 2,
- "renderer" => "networkd",
- "ethernets" => {},
- "bonds" => {},
- "vlans" => {}
- }
- }
-
- node[:networking][:interfaces].each do |name, interface|
- if interface[:interface]
- if interface[:role] && (role = node[:networking][:roles][interface[:role]])
- if interface[:inet] && role[:inet]
- node.default[:networking][:interfaces][name][:inet][:prefix] = role[:inet][:prefix]
- node.default[:networking][:interfaces][name][:inet][:gateway] = role[:inet][:gateway]
- node.default[:networking][:interfaces][name][:inet][:routes] = role[:inet][:routes]
- end
-
- if interface[:inet6] && role[:inet6]
- node.default[:networking][:interfaces][name][:inet6][:prefix] = role[:inet6][:prefix]
- node.default[:networking][:interfaces][name][:inet6][:gateway] = role[:inet6][:gateway]
- node.default[:networking][:interfaces][name][:inet6][:routes] = role[:inet6][:routes]
- end
-
- node.default[:networking][:interfaces][name][:metric] = role[:metric]
- node.default[:networking][:interfaces][name][:zone] = role[:zone]
- end
-
- interface = node[:networking][:interfaces][name]
-
- deviceplan = if interface[:interface] =~ /^(.*)\.(\d+)$/
- netplan["network"]["vlans"][interface[:interface]] ||= {
- "id" => Regexp.last_match(2).to_i,
- "link" => Regexp.last_match(1),
- "accept-ra" => false,
- "addresses" => [],
- "routes" => []
- }
- elsif interface[:interface] =~ /^bond\d+$/
- netplan["network"]["bonds"][interface[:interface]] ||= {
- "accept-ra" => false,
- "addresses" => [],
- "routes" => []
- }
- else
- netplan["network"]["ethernets"][interface[:interface]] ||= {
- "accept-ra" => false,
- "addresses" => [],
- "routes" => []
- }
- end
-
- if interface[:inet]
- deviceplan["addresses"].push("#{interface[:inet][:address]}/#{interface[:inet][:prefix]}")
- end
-
- if interface[:inet6]
- deviceplan["addresses"].push("#{interface[:inet6][:address]}/#{interface[:inet6][:prefix]}")
- end