diff options
author | Stuart Sears <stuart@sjsears.com> | 2019-09-17 12:24:12 +0100 |
---|---|---|
committer | Stuart Sears <stuart@sjsears.com> | 2019-09-17 12:24:49 +0100 |
commit | 72504526cb7b6d2f09d5da771ab362eae583042d (patch) | |
tree | 635cc3d0977d53baf67edcc11f698885209f3393 | |
parent | f6d445c28467b5ea5741d05aed2bd1f657c4a1dd (diff) | |
download | chef-72504526cb7b6d2f09d5da771ab362eae583042d.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 |