summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/resource/kernel_module.rb29
-rw-r--r--spec/unit/resource/kernel_module_spec.rb3
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/chef/resource/kernel_module.rb b/lib/chef/resource/kernel_module.rb
index c4a36af9eb..4084dcbd70 100644
--- a/lib/chef/resource/kernel_module.rb
+++ b/lib/chef/resource/kernel_module.rb
@@ -15,7 +15,7 @@ class Chef
provides :kernel_module
- description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, install, and uninstall modules."
+ description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, enable, install, and uninstall modules."
introduced "14.3"
examples <<~DOC
Install and load a kernel module, and ensure it loads on reboot.
@@ -68,13 +68,21 @@ class Chef
end
```
- Disable a kernel module.
+ Disable a kernel module so that it is not installable.
```ruby
kernel_module 'loop' do
action :disable
end
```
+
+ Enable a kernel module so that it is can be installed. Does not load or install.
+
+ ```ruby
+ kernel_module 'loop' do
+ action :enable
+ end
+ ```
DOC
property :modname, String,
@@ -101,6 +109,9 @@ class Chef
end
end
+ # Remove the "disable file" before trying to install
+ action_enable
+
# create options file before loading the module
unless new_resource.options.nil?
file "#{new_resource.unload_dir}/options_#{new_resource.modname}.conf" do
@@ -178,6 +189,20 @@ class Chef
action_unload
end
+ action :enable, description: "Enable a kernel module. Reverse :disable actions" do
+ with_run_context :root do
+ find_resource(:execute, "update initramfs") do
+ command initramfs_command
+ action :nothing
+ end
+ end
+
+ file "#{new_resource.unload_dir}/disable_#{new_resource.modname}.conf" do
+ action :delete
+ notifies :run, "execute[update initramfs]", :delayed
+ end
+ end
+
action :load, description: "Load a kernel module." do
unless module_loaded?
converge_by("load kernel module #{new_resource.modname}") do
diff --git a/spec/unit/resource/kernel_module_spec.rb b/spec/unit/resource/kernel_module_spec.rb
index aed31e03c8..b283fba0b8 100644
--- a/spec/unit/resource/kernel_module_spec.rb
+++ b/spec/unit/resource/kernel_module_spec.rb
@@ -32,10 +32,11 @@ describe Chef::Resource::KernelModule do
expect(resource.modname).to eql("foo")
end
- it "supports :create and :flush actions" do
+ it "supports various actions" do
expect { resource.action :install }.not_to raise_error
expect { resource.action :uninstall }.not_to raise_error
expect { resource.action :blacklist }.not_to raise_error
+ expect { resource.action :enable }.not_to raise_error
expect { resource.action :disable }.not_to raise_error
expect { resource.action :load }.not_to raise_error
expect { resource.action :unload }.not_to raise_error