Use the sysctl resource to manage sysctl settings
authorTom Hughes <tom@compton.nu>
Thu, 13 Feb 2020 19:21:40 +0000 (19:21 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 13 Feb 2020 19:21:40 +0000 (19:21 +0000)
cookbooks/sysctl/recipes/default.rb
cookbooks/sysctl/templates/default/chef.conf.erb [deleted file]

index 14295b37726baba083b2479cdc5f4b4c5f73955a..0190b37b7d14230af1ea88e3b586b6d231c2d0e3 100644 (file)
 # limitations under the License.
 #
 
-if node[:virtualization][:role] == "guest" &&
-   node[:virtualization][:system] == "lxd"
-  file "/etc/sysctl.d/60-chef.conf" do
-    action :delete
-  end
-else
-  package "procps"
-
-  directory "/etc/sysctl.d" do
-    owner "root"
-    group "root"
-    mode 0o755
-  end
-
-  execute "sysctl" do
-    action :nothing
-    command "/sbin/sysctl -p /etc/sysctl.d/60-chef.conf"
-  end
-
-  template "/etc/sysctl.d/60-chef.conf" do
-    source "chef.conf.erb"
-    owner "root"
-    group "root"
-    mode 0o644
-    notifies :run, "execute[sysctl]"
-  end
+file "/etc/sysctl.d/60-chef.conf" do
+  action :delete
+end
 
+if node[:virtualization][:role] != "guest" ||
+   node[:virtualization][:system] != "lxd"
   node[:sysctl].each_value do |group|
     group[:parameters].each do |key, value|
-      sysctl_file = "/proc/sys/#{key.tr('.', '/')}"
-
-      file sysctl_file do
-        content "#{value}\n"
-        atomic_update false
-        ignore_failure true
+      sysctl key do
+        value value
+        comment group[:comment]
       end
     end
   end
diff --git a/cookbooks/sysctl/templates/default/chef.conf.erb b/cookbooks/sysctl/templates/default/chef.conf.erb
deleted file mode 100644 (file)
index 991664f..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# DO NOT EDIT - This file is being maintained by Chef
-<% node[:sysctl].each do |name,group| -%>
-
-# <%= group[:comment] %>
-<% group[:parameters].each do |key,value| -%>
-<%= key %> = <%= value %>
-<% end -%>
-<% end -%>