summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-12-02 16:28:18 -0800
committerGitHub <noreply@github.com>2019-12-02 16:28:18 -0800
commit2e9471af956ef8a6de6ec5d41dc448b0f970df20 (patch)
tree8a53d3bb9b317f42cf55a91e4c3f7d4204fed523
parentf500a7b7ff39b1817e3314a4570983aa87fa7e6c (diff)
parentdf3791a6d6988da6d2eb4d444d60e032d5c4f819 (diff)
downloadchef-2e9471af956ef8a6de6ec5d41dc448b0f970df20.tar.gz
Merge pull request #9120 from ramereth/ramereth/kernel_module-modprobe-file-chef14
kernel_module: Add new options property (backport from chef-15 to chef-14)
-rw-r--r--lib/chef/resource/kernel_module.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/chef/resource/kernel_module.rb b/lib/chef/resource/kernel_module.rb
index 0f2053334e..cd3453cdf1 100644
--- a/lib/chef/resource/kernel_module.rb
+++ b/lib/chef/resource/kernel_module.rb
@@ -16,11 +16,61 @@ class Chef
description "Use the kernel_module resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, install, and uninstall modules."
introduced "14.3"
+ examples <<~DOC
+ Install and load a kernel module, and ensure it loads on reboot.
+ ```ruby
+ kernel_module 'loop'
+ ```
+ Install and load a kernel with a specific set of options, and ensure it loads on reboot. Consult kernel module
+ documentation for specific options that are supported.
+ ```ruby
+ kernel_module 'loop' do
+ options [
+ 'max_loop=4',
+ 'max_part=8'
+ ]
+ end
+ ```
+ Load a kernel module.
+ ```ruby
+ kernel_module 'loop' do
+ action :load
+ end
+ ```
+ Unload a kernel module and remove module config, so it doesn’t load on reboot.
+ ```ruby
+ kernel_module 'loop' do
+ action :uninstall
+ end
+ ```
+ Unload kernel module.
+ ```ruby
+ kernel_module 'loop' do
+ action :unload
+ end
+ ```
+ Blacklist a module from loading.
+ ```ruby
+ kernel_module 'loop' do
+ action :blacklist
+ end
+ ```
+ Disable a kernel module.
+ ```ruby
+ kernel_module 'loop' do
+ action :disable
+ end
+ ```
+ DOC
property :modname, String,
description: "An optional property to set the kernel module name if it differs from the resource block's name.",
name_property: true, identity: true
+ property :options, Array,
+ description: "An optional property to set options for the kernel module.",
+ introduced: "14.15"
+
property :load_dir, String,
description: "The directory to load modules from.",
default: "/etc/modules-load.d"
@@ -32,6 +82,13 @@ class Chef
action :install do
description "Load kernel module, and ensure it loads on reboot."
+ # create options file before loading the module
+ unless new_resource.options.nil?
+ file "#{new_resource.unload_dir}/options_#{new_resource.modname}.conf" do
+ content "options #{new_resource.modname} #{new_resource.options.join(" ")}\n"
+ end.run_action(:create)
+ end
+
# load the module first before installing
new_resource.run_action(:load)
@@ -65,6 +122,10 @@ class Chef
notifies :run, "execute[update initramfs]", :delayed
end
+ file "#{new_resource.unload_dir}/options_#{new_resource.modname}.conf" do
+ action :delete
+ end
+
with_run_context :root do
find_resource(:execute, "update initramfs") do
command initramfs_command