]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/recipes/default.rb
Improve naming of wireguard configuration files
[chef.git] / cookbooks / networking / recipes / default.rb
index a7006d436e0897914a2ecb649975ef76e607b357..540d858fcfe0eafdb70c7d8361333528d13328b2 100644 (file)
@@ -309,49 +309,41 @@ if node[:networking][:wireguard][:enabled]
     end
   end
 
-  template "/etc/systemd/network/wireguard.netdev" do
+  file "/etc/systemd/network/wireguard.netdev" do
+    action :delete
+  end
+
+  template "/etc/systemd/network/10-wg0.netdev" do
     source "wireguard.netdev.erb"
     owner "root"
     group "systemd-network"
     mode "640"
+    notifies :run, "execute[networkctl-delete-wg0]"
+    notifies :run, "execute[networkctl-reload]"
+  end
+
+  file "/etc/systemd/network/wireguard.network" do
+    action :delete
   end
 
-  template "/etc/systemd/network/wireguard.network" do
+  template "/etc/systemd/network/10-wg0.network" do
     source "wireguard.network.erb"
     owner "root"
     group "root"
     mode "644"
+    notifies :run, "execute[networkctl-reload]"
   end
 
-  if node[:lsb][:release].to_f < 20.04
-    execute "ip-link-delete-wg0" do
-      action :nothing
-      command "ip link delete wg0"
-      subscribes :run, "template[/etc/systemd/network/wireguard.netdev]"
-      only_if { ::File.exist?("/sys/class/net/wg0") }
-    end
-
-    service "systemd-networkd" do
-      action :nothing
-      subscribes :restart, "template[/etc/systemd/network/wireguard.netdev]"
-      subscribes :restart, "template[/etc/systemd/network/wireguard.network]"
-      not_if { kitchen? }
-    end
-  else
-    execute "networkctl-delete-wg0" do
-      action :nothing
-      command "networkctl delete wg0"
-      subscribes :run, "template[/etc/systemd/network/wireguard.netdev]"
-      only_if { ::File.exist?("/sys/class/net/wg0") }
-    end
+  execute "networkctl-delete-wg0" do
+    action :nothing
+    command "networkctl delete wg0"
+    only_if { ::File.exist?("/sys/class/net/wg0") }
+  end
 
-    execute "networkctl-reload" do
-      action :nothing
-      command "networkctl reload"
-      subscribes :run, "template[/etc/systemd/network/wireguard.netdev]"
-      subscribes :run, "template[/etc/systemd/network/wireguard.network]"
-      not_if { kitchen? }
-    end
+  execute "networkctl-reload" do
+    action :nothing
+    command "networkctl reload"
+    not_if { kitchen? }
   end
 end