diff options
author | Tim Smith <tsmith@chef.io> | 2020-02-03 10:57:21 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-03 10:57:21 -0800 |
commit | 2eb82de1cc535d5552f47e8e4125ad6cb7b19938 (patch) | |
tree | 44c297b20cf674a6404013181b83bdcfeff74dcf | |
parent | f1dc0c37b9ac7a1ebdbc39721624559213532e10 (diff) | |
parent | edded246ec91f2fc41a6517f26f3fdb45b064873 (diff) | |
download | chef-2eb82de1cc535d5552f47e8e4125ad6cb7b19938.tar.gz |
Merge pull request #8409 from lanky/sysctl_comment_block
Add comment block to sysctl resource
-rw-r--r-- | RELEASE_NOTES.md | 33 | ||||
-rw-r--r-- | lib/chef/resource/sysctl.rb | 11 |
2 files changed, 43 insertions, 1 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c29b144c49..a525bf29fa 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -494,6 +494,39 @@ Our underlying SSH implementation has been updated to support the new ed25519 SS Chef Solo's `--delete-entire-chef-repo` option has been extended to work in Local Mode as well. Be warned that this flag does exactly what it states, and when used incorrectly, can result in loss of work. +### sysctl now accepts a comments parameter + +The `sysctl` resource has been updated to allow the inclusion of descriptive comments. Comments may be passed as an array or a string. Any comments provided are prefixed with '#' signs and precede the `sysctl` setting in generated files. + +An example: + +``` +sysctl 'vm.swappiness' do + value 10 + comment [ + "define how aggressively the kernel will swap memory pages.", + "Higher values will increase aggressiveness", + "lower values decrease the amount of swap.", + "A value of 0 instructs the kernel not to initiate swap", + "until the amount of free and file-backed pages is less", + "than the high water mark in a zone.", + "The default value is 60." + ] +end +``` + +which results in `/etc/sysctl.d/99-chef-vm.swappiness.conf` as follows +``` +# define how aggressively the kernel will swap memory pages. +# Higher values will increase aggressiveness +# lower values decrease the amount of swap. +# A value of 0 instructs the kernel not to initiate swap +# until the amount of free and file-backed pages is less +# than the high water mark in a zone. +# The default value is 60. +vm.swappiness = 10 +``` + ## New Resources ### archive_file resource diff --git a/lib/chef/resource/sysctl.rb b/lib/chef/resource/sysctl.rb index a6c316c5bc..af1df9746c 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 + # 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 "#{new_resource.key} = #{new_resource.value}" + content sysctl_lines.join("\n") end execute "Load sysctl values" do |