-template "/etc/resolv.conf" do
- source "resolv.conf.erb"
- owner "root"
- group "root"
- mode 0644
-end
-
-node.interfaces(:role => :internal) do |interface|
- if interface[:gateway] and interface[:gateway] != interface[:address]
- search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
- if gateway[:openvpn]
- gateway[:openvpn][:tunnels].each_value do |tunnel|
- if tunnel[:peer][:address]
- route tunnel[:peer][:address] do
- netmask "255.255.255.255"
- gateway interface[:gateway]
- device interface[:interface]
- end
- end
-
- if tunnel[:peer][:networks]
- tunnel[:peer][:networks].each do |network|
- route network[:address] do
- netmask network[:netmask]
- gateway interface[:gateway]
- device interface[:interface]
- end
- end
- end
- end
+interfaces = node[:networking][:interfaces].collect do |name, interface|
+ [interface[:interface], name]
+end.to_h
+
+node[:networking][:interfaces].each do |name, interface|
+ if interface[:interface] =~ /^(.*)\.(\d+)$/
+ vlan_interface = Regexp.last_match(1)
+ vlan_id = Regexp.last_match(2)
+
+ parent = interfaces[vlan_interface] || "vlans_#{vlan_interface}"
+
+ node.default_unless[:networking][:interfaces][parent][:interface] = vlan_interface
+ node.default_unless[:networking][:interfaces][parent][:vlans] = []
+
+ node.default[:networking][:interfaces][parent][:vlans] << vlan_id
+ end
+
+ next unless interface[:role] && (role = node[:networking][:roles][interface[:role]])
+
+ if interface[:inet] && role[:inet]
+ node.default_unless[:networking][:interfaces][name][:inet][:prefix] = role[:inet][:prefix]
+ node.default_unless[:networking][:interfaces][name][:inet][:gateway] = role[:inet][:gateway]
+ node.default_unless[:networking][:interfaces][name][:inet][:routes] = role[:inet][:routes]
+ end
+
+ if interface[:inet6] && role[:inet6]
+ node.default_unless[:networking][:interfaces][name][:inet6][:prefix] = role[:inet6][:prefix]
+ node.default_unless[:networking][:interfaces][name][:inet6][:gateway] = role[:inet6][:gateway]
+ node.default_unless[:networking][:interfaces][name][:inet6][:routes] = role[:inet6][:routes]
+ end
+
+ node.default_unless[:networking][:interfaces][name][:metric] = role[:metric]
+ node.default_unless[:networking][:interfaces][name][:zone] = role[:zone]
+end
+
+node[:networking][:interfaces].each do |_, interface|
+ if interface[:interface] =~ /^.*\.(\d+)$/
+ template "/etc/systemd/network/10-#{interface[:interface]}.netdev" do
+ source "vlan.netdev.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ variables :interface => interface, :vlan => Regexp.last_match(1)
+ notifies :run, "notify_group[networkctl-reload]"
+ end
+ elsif interface[:interface] =~ /^bond\d+$/
+ template "/etc/systemd/network/10-#{interface[:interface]}.netdev" do
+ source "bond.netdev.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ variables :interface => interface
+ notifies :run, "notify_group[networkctl-reload]"
+ end
+
+ interface[:bond][:slaves].each do |slave|
+ template "/etc/systemd/network/10-#{slave}.network" do
+ source "slave.network.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ variables :master => interface, :slave => slave
+ notifies :run, "notify_group[networkctl-reload]"