]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/recipes/default.rb
Update bundle
[chef.git] / cookbooks / networking / recipes / default.rb
index cfc04cbef93868de5561c40eb9f1e9038ae1eb0b..5c73c5cc3197be9d99e10ecf32d0377f33d1fab0 100644 (file)
@@ -48,10 +48,12 @@ node[:networking][:interfaces].each do |name, interface|
       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]
 
@@ -77,7 +79,9 @@ node[:networking][:interfaces].each do |name, interface|
                    }
                  end
 
-    deviceplan["addresses"].push("#{interface[:address]}/#{prefix}")
+    if interface[:address]
+      deviceplan["addresses"].push("#{interface[:address]}/#{prefix}")
+    end
 
     if interface[:mtu]
       deviceplan["mtu"] = interface[:mtu]
@@ -177,17 +181,15 @@ package "cloud-init" do
   action :purge
 end
 
-execute "hostname" do
+ohai "reload-hostname" do
   action :nothing
-  command "/bin/hostname -F /etc/hostname"
+  plugin "hostname"
 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
@@ -195,6 +197,7 @@ template "/etc/hosts" do
   owner "root"
   group "root"
   mode 0o644
+  not_if { ENV["TEST_KITCHEN"] }
 end
 
 service "systemd-resolved" do
@@ -215,6 +218,13 @@ template "/etc/systemd/resolved.conf.d/99-chef.conf" do
   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