From cb646590a622f93f6eb78f5b6d8a0cfbb0e23ab2 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 13 Feb 2020 19:21:40 +0000 Subject: [PATCH] Use the sysctl resource to manage sysctl settings --- cookbooks/sysctl/recipes/default.rb | 40 ++++--------------- .../sysctl/templates/default/chef.conf.erb | 8 ---- 2 files changed, 8 insertions(+), 40 deletions(-) delete mode 100644 cookbooks/sysctl/templates/default/chef.conf.erb diff --git a/cookbooks/sysctl/recipes/default.rb b/cookbooks/sysctl/recipes/default.rb index 14295b377..0190b37b7 100644 --- a/cookbooks/sysctl/recipes/default.rb +++ b/cookbooks/sysctl/recipes/default.rb @@ -17,41 +17,17 @@ # 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 index 991664f3a..000000000 --- a/cookbooks/sysctl/templates/default/chef.conf.erb +++ /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 -%> -- 2.39.5