chef-lctp/site-cookbooks/lctp-network/recipes/default.rb

45 lines
852 B
Ruby

include_recipe "network_interfaces"
package "ifmetric"
cookbook_file "/etc/network/interfaces" do
source "interfaces"
mode 0644
owner "root"
group "root"
end
network = node.lctp_network
unless network.domain_servers.empty? and network.search_domains.empty?
file "/etc/dhcp/dhclient-enter-hooks.d/resolvconf" do
action :delete
end
template "/etc/resolv.conf" do
source "resolv.conf.erb"
variables(network: network)
end
end
network.interfaces.each do |device, iface|
network_interfaces device do
if iface.attribute? "metric"
metric iface.metric
end
if iface.attribute? "static_ip"
target iface.static_ip
if iface.attribute? "netmask"
mask iface.netmask
else
mask "255.255.255.0"
end
bootproto "static"
else
bootproto "dhcp"
end
end
end