summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-05-04 15:14:49 -0700
committerTim Smith <tsmith84@gmail.com>2020-05-04 15:22:21 -0700
commit42e8fb3ac885547f931acb4a92dbc812c51de29c (patch)
treef955511fd1c947cbc176a12651aee351a2f791c1
parentdd0e2dbb8b299157c9bf82c9ac7d7dd374b31ca7 (diff)
downloadchef-42e8fb3ac885547f931acb4a92dbc812c51de29c.tar.gz
Fix sysctl :remove action failing with missing :value prop
Don't require this when removing. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_alternatives.rb (renamed from kitchen-tests/cookbooks/end_to_end/recipes/alternatives.rb)0
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_chef-vault.rb (renamed from kitchen-tests/cookbooks/end_to_end/recipes/chef-vault.rb)0
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_packages.rb (renamed from kitchen-tests/cookbooks/end_to_end/recipes/packages.rb)0
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb12
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_tests.rb (renamed from kitchen-tests/cookbooks/end_to_end/recipes/tests.rb)0
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/default.rb9
-rw-r--r--lib/chef/resource/sysctl.rb62
7 files changed, 78 insertions, 5 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/alternatives.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_alternatives.rb
index 8e0a0bb178..8e0a0bb178 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/alternatives.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_alternatives.rb
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/chef-vault.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_chef-vault.rb
index aa01982e3d..aa01982e3d 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/chef-vault.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_chef-vault.rb
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/packages.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_packages.rb
index 58ede61f52..58ede61f52 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/packages.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_packages.rb
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb
new file mode 100644
index 0000000000..8c644e01c6
--- /dev/null
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb
@@ -0,0 +1,12 @@
+#
+# Cookbook:: end_to_end
+# Recipe:: sysctl
+#
+
+sysctl "vm.swappiness" do
+ value 19
+end
+
+sysctl "kernel.msgmax" do
+ action :remove
+end \ No newline at end of file
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_tests.rb
index d74a310394..d74a310394 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_tests.rb
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/default.rb b/kitchen-tests/cookbooks/end_to_end/recipes/default.rb
index 54750039c5..6378d55bcc 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/default.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/default.rb
@@ -40,7 +40,7 @@ build_essential do
raise_if_unsupported true
end
-include_recipe "::packages"
+include_recipe "::_packages"
include_recipe "ntp"
@@ -158,6 +158,7 @@ locale "set system locale" do
only_if { debian? }
end
-include_recipe "::chef-vault" unless includes_recipe?("end_to_end::chef-vault")
-include_recipe "::alternatives"
-include_recipe "::tests"
+include_recipe "::_chef-vault" unless includes_recipe?("end_to_end::chef-vault")
+include_recipe "::_sysctl"
+include_recipe "::_alternatives"
+include_recipe "::_tests"
diff --git a/lib/chef/resource/sysctl.rb b/lib/chef/resource/sysctl.rb
index c2ac8224b4..78d1072ddb 100644
--- a/lib/chef/resource/sysctl.rb
+++ b/lib/chef/resource/sysctl.rb
@@ -30,6 +30,66 @@ class Chef
"Configuration files managed by this resource are named 99-chef-KEYNAME.conf. If"\
" an existing value was already set for the value it will be backed up to the node"\
" and restored if the :remove action is used later."
+ examples <<~DOC
+ **Set vm.swappiness**:
+
+ ```ruby
+ sysctl 'vm.swappiness' do
+ value 19
+ end
+ ```
+
+ **Remove kernel.msgmax**
+
+ **Note**: This only removes the sysctl.d config for kernel.msgmax. The value will be set back to the kernel default value.
+
+ ```ruby
+ sysctl 'kernel.msgmax' do
+ action :remove
+ end
+ ```
+
+ **Adding Comments to sysctl configuration files**
+
+ ```ruby
+ sysctl 'vm.swappiness' do
+ value 19
+ comment "define how aggressively the kernel will swap memory pages."
+ end
+ ```
+
+ This produces /etc/sysctl.d/99-chef-vm.swappiness.conf as follows:
+
+ ```
+ # define how aggressively the kernel will swap memory pages.
+ vm.swappiness = 1
+ ```
+
+ **Converting sysctl settings from shell scripts**:
+
+ Example of existing settings:
+
+ ```bash
+ fs.aio-max-nr = 1048576 net.ipv4.ip_local_port_range = 9000 65500 kernel.sem = 250 32000 100 128
+ ```
+
+ Converted to sysctl resources:
+
+ ```ruby
+ sysctl 'fs.aio-max-nr' do
+ value '1048576'
+ end
+
+ sysctl 'net.ipv4.ip_local_port_range' do
+ value '9000 65500'
+ end
+
+ sysctl 'kernel.sem' do
+ value '250 32000 100 128'
+ end
+ ```
+ DOC
+
introduced "14.0"
@@ -44,7 +104,7 @@ class Chef
property :value, [Array, String, Integer, Float],
description: "The value to set.",
coerce: proc { |v| coerce_value(v) },
- required: true
+ required: %i(:apply)
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.",