summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Doherty <tom.doherty@fixnetix.com>2019-07-17 16:36:18 +0100
committerTom Doherty <tom.doherty@fixnetix.com>2019-07-17 16:36:18 +0100
commitf617b243c25d9e68ddfc5ca66e60ae2574f772b4 (patch)
treea428a3e985524afe3c6237e1bb1e5e1d0bd124ca
parentf046ceca7f21ee61d7386e21779a6f60e7bdc49f (diff)
downloadchef-f617b243c25d9e68ddfc5ca66e60ae2574f772b4.tar.gz
Implement disable for disabling kernel_modules
This allows inspec kernel_module be_disabled to work Signed-off-by: Tom Doherty <tom.doherty@fixnetix.com>
-rw-r--r--lib/chef/resource/kernel_module.rb20
-rw-r--r--spec/unit/resource/kernel_module_spec.rb1
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/chef/resource/kernel_module.rb b/lib/chef/resource/kernel_module.rb
index 882f9de975..1176990071 100644
--- a/lib/chef/resource/kernel_module.rb
+++ b/lib/chef/resource/kernel_module.rb
@@ -13,7 +13,7 @@ class Chef
class KernelModule < Chef::Resource
resource_name :kernel_module
- description "Use the kernel_module resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, install, and uninstall modules."
+ description "Use the kernel_module resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, install, and uninstall modules."
introduced "14.3"
property :modname, String,
@@ -92,6 +92,24 @@ class Chef
new_resource.run_action(:unload)
end
+ action :disable do
+ description "Disable a kernel module."
+
+ file "#{new_resource.unload_dir}/disable_#{new_resource.modname}.conf" do
+ content "install #{new_resource.modname} /bin/false"
+ notifies :run, "execute[update initramfs]", :delayed
+ end
+
+ with_run_context :root do
+ find_resource(:execute, "update initramfs") do
+ command initramfs_command
+ action :nothing
+ end
+ end
+
+ new_resource.run_action(:unload)
+ end
+
action :load do
description "Load a kernel module."
diff --git a/spec/unit/resource/kernel_module_spec.rb b/spec/unit/resource/kernel_module_spec.rb
index 6cbc047e79..9242959bd6 100644
--- a/spec/unit/resource/kernel_module_spec.rb
+++ b/spec/unit/resource/kernel_module_spec.rb
@@ -36,6 +36,7 @@ describe Chef::Resource::KernelModule 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 :disable }.not_to raise_error
expect { resource.action :load }.not_to raise_error
expect { resource.action :unload }.not_to raise_error
expect { resource.action :delete }.to raise_error(ArgumentError)