]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/recipes/default.rb
Enable wikidiff2 for FPM
[chef.git] / cookbooks / networking / recipes / default.rb
index 822f9042f1c0c89929b05e228e05aa679c4b2ed6..5c73c5cc3197be9d99e10ecf32d0377f33d1fab0 100644 (file)
@@ -1,9 +1,9 @@
 #
 #
-# Cookbook Name:: networking
+# Cookbook:: networking
 # Recipe:: default
 #
 # Recipe:: default
 #
-# Copyright 2010, OpenStreetMap Foundation.
-# Copyright 2009, Opscode, Inc.
+# Copyright:: 2010, OpenStreetMap Foundation.
+# Copyright:: 2009, Opscode, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@
 require "ipaddr"
 require "yaml"
 
 require "ipaddr"
 require "yaml"
 
+package "netplan.io"
+
 netplan = {
   "network" => {
     "version" => 2,
 netplan = {
   "network" => {
     "version" => 2,
@@ -39,16 +41,19 @@ node[:networking][:interfaces].each do |name, interface|
       if role[interface[:family]]
         node.normal[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
         node.normal[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
       if role[interface[:family]]
         node.normal[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
         node.normal[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
+        node.normal[:networking][:interfaces][name][:routes] = role[interface[:family]][:routes]
       end
 
       node.normal[:networking][:interfaces][name][:metric] = role[:metric]
       node.normal[:networking][:interfaces][name][:zone] = role[:zone]
     end
 
       end
 
       node.normal[:networking][:interfaces][name][:metric] = role[:metric]
       node.normal[:networking][:interfaces][name][:zone] = role[:zone]
     end
 
-    prefix = node[:networking][:interfaces][name][:prefix]
+    if interface[:address]
+      prefix = node[:networking][:interfaces][name][:prefix]
 
 
-    node.normal[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
-    node.normal[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix)
+      node.normal[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
+      node.normal[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix)
+    end
 
     interface = node[:networking][:interfaces][name]
 
 
     interface = node[:networking][:interfaces][name]
 
@@ -74,7 +79,9 @@ node[:networking][:interfaces].each do |name, interface|
                    }
                  end
 
                    }
                  end
 
-    deviceplan["addresses"].push("#{interface[:address]}/#{prefix}")
+    if interface[:address]
+      deviceplan["addresses"].push("#{interface[:address]}/#{prefix}")
+    end
 
     if interface[:mtu]
       deviceplan["mtu"] = interface[:mtu]
 
     if interface[:mtu]
       deviceplan["mtu"] = interface[:mtu]
@@ -124,6 +131,20 @@ node[:networking][:interfaces].each do |name, interface|
         )
       end
     end
         )
       end
     end
+
+    if interface[:routes]
+      interface[:routes].each do |to, parameters|
+        route = {
+          "to" => to
+        }
+
+        route["type"] = parameters[:type] if parameters[:type]
+        route["via"] = parameters[:via] if parameters[:via]
+        route["metric"] = parameters[:metric] if parameters[:metric]
+
+        deviceplan["routes"].push(route)
+      end
+    end
   else
     node.rm(:networking, :interfaces, name)
   end
   else
     node.rm(:networking, :interfaces, name)
   end
@@ -160,17 +181,15 @@ package "cloud-init" do
   action :purge
 end
 
   action :purge
 end
 
-execute "hostname" do
+ohai "reload-hostname" do
   action :nothing
   action :nothing
-  command "/bin/hostname -F /etc/hostname"
+  plugin "hostname"
 end
 
 end
 
-template "/etc/hostname" do
-  source "hostname.erb"
-  owner "root"
-  group "root"
-  mode 0o644
-  notifies :run, "execute[hostname]"
+execute "hostnamectl-set-hostname" do
+  command "hostnamectl set-hostname #{node[:networking][:hostname]}"
+  notifies :reload, "ohai[reload-hostname]"
+  not_if { ENV.key?("TEST_KITCHEN") || node[:hostnamectl][:static_hostname] == node[:networking][:hostname] }
 end
 
 template "/etc/hosts" do
 end
 
 template "/etc/hosts" do
@@ -178,6 +197,7 @@ template "/etc/hosts" do
   owner "root"
   group "root"
   mode 0o644
   owner "root"
   group "root"
   mode 0o644
+  not_if { ENV["TEST_KITCHEN"] }
 end
 
 service "systemd-resolved" do
 end
 
 service "systemd-resolved" do
@@ -195,7 +215,29 @@ template "/etc/systemd/resolved.conf.d/99-chef.conf" do
   owner "root"
   group "root"
   mode 0o644
   owner "root"
   group "root"
   mode 0o644
-  notifies :restart, "service[systemd-resolved]"
+  notifies :restart, "service[systemd-resolved]", :immediately
+end
+
+if node[:filesystem][:by_mountpoint][:"/etc/resolv.conf"]
+  mount "/etc/resolv.conf" do
+    action :umount
+    device node[:filesystem][:by_mountpoint][:"/etc/resolv.conf"][:devices].first
+  end
+end
+
+link "/etc/resolv.conf" do
+  to "../run/systemd/resolve/stub-resolv.conf"
+end
+
+if node[:networking][:tcp_fastopen_key]
+  fastopen_keys = data_bag_item("networking", "fastopen")
+
+  node.normal[:sysctl][:tcp_fastopen] = {
+    :comment => "Set shared key for TCP fast open",
+    :parameters => {
+      "net.ipv4.tcp_fastopen_key" => fastopen_keys[node[:networking][:tcp_fastopen_key]]
+    }
+  }
 end
 
 node.interfaces(:role => :internal) do |interface|
 end
 
 node.interfaces(:role => :internal) do |interface|
@@ -204,7 +246,7 @@ node.interfaces(:role => :internal) do |interface|
       next unless gateway[:openvpn]
 
       gateway[:openvpn][:tunnels].each_value do |tunnel|
       next unless gateway[:openvpn]
 
       gateway[:openvpn][:tunnels].each_value do |tunnel|
-        if tunnel[:peer][:address] # ~FC023
+        if tunnel[:peer][:address]
           route tunnel[:peer][:address] do
             netmask "255.255.255.255"
             gateway interface[:gateway]
           route tunnel[:peer][:address] do
             netmask "255.255.255.255"
             gateway interface[:gateway]