diff options
author | Stuart Sears <stuart@sjsears.com> | 2019-09-17 12:24:12 +0100 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-02-03 13:12:20 -0800 |
commit | c0f2b9da9aa6702275644f39627995076dd5dd19 (patch) | |
tree | 1ea96fd7ca1a5dfdd6eb46eca4294d41b01051b1 | |
parent | b515d50aaf7c7d6834724e709803b2883a6f484d (diff) | |
download | chef-c0f2b9da9aa6702275644f39627995076dd5dd19.tar.gz |
Consolidated changes to sysctl.rb
- adds comment block support to sysctl resource
Signed-off-by: Stuart Sears <stuart@sjsears.com>
-rw-r--r-- | lib/chef/resource/sysctl.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/chef/resource/sysctl.rb b/lib/chef/resource/sysctl.rb index a6c316c5bc..03ddad204b 100644 --- a/lib/chef/resource/sysctl.rb +++ b/lib/chef/resource/sysctl.rb @@ -45,6 +45,10 @@ class Chef coerce: proc { |v| coerce_value(v) }, required: true + property :comment, [Array, String], + description: "Comments, placed above the resource setting in the generated file. For multi-line comments, use an array of strings, one per line.", + default: [] + property :conf_dir, String, description: "The configuration directory to write the config to.", default: "/etc/sysctl.d" @@ -80,8 +84,13 @@ class Chef directory new_resource.conf_dir - file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr("/", ".")}.conf" do - content "#{new_resource.key} = #{new_resource.value}" + # construct a string, joining members of new_resource.comment + sysctl_lines = Array(new_resource.comment).map { |c| "# #{c.strip}" } + + sysctl_lines << "#{new_resource.key} = #{new_resource.value}" + + file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf" do + content sysctl_lines.join("\n") end execute "Load sysctl values" do |