]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/recipes/default.rb
Update bundle
[chef.git] / cookbooks / networking / recipes / default.rb
index 321109a1de0d04127c0ee4a0ecb90784f5552768..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,7 +181,16 @@ package "cloud-init" do
   action :purge
 end
 
-hostname node[:networking][:hostname]
+ohai "reload-hostname" do
+  action :nothing
+  plugin "hostname"
+end
+
+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
   source "hosts.erb"