diff options
author | Tim Smith <tsmith@chef.io> | 2018-04-21 18:38:18 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-06-11 12:40:59 -0700 |
commit | ce666826c4e4671eb23e9c8c22577bd89ef782cb (patch) | |
tree | eaa297b46f3ae82f2ca07da27f283a801d599c81 | |
parent | 50a993b567284ba43a34a67d6924b40a8932706f (diff) | |
download | chef-ce666826c4e4671eb23e9c8c22577bd89ef782cb.tar.gz |
Use shell_out and a file read instead of execute
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/kernel_module.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/chef/resource/kernel_module.rb b/lib/chef/resource/kernel_module.rb index 9b1836e266..e7c11cb67f 100644 --- a/lib/chef/resource/kernel_module.rb +++ b/lib/chef/resource/kernel_module.rb @@ -74,19 +74,25 @@ class Chef # Load kernel module action :load do - declare_resource(:execute, "modprobe #{new_resource.modname}") do - not_if "cat /proc/modules | grep ^#{new_resource.modname}" + unless module_loaded? + converge_by("load kernel module #{new_resource.modname}") do + shell_out!("modprobe #{new_resource.modname}") + end end end # Unload kernel module action :unload do - declare_resource(:execute, "modprobe -r #{new_resource.modname}") do - only_if "cat /proc/modules | grep ^#{new_resource.modname}" + if module_loaded? + converge_by("unload kernel module #{new_resource.modname}") do + shell_out!("modprobe -r #{new_resource.modname}") + end end end action_class do + # determine the correct command to regen the initramfs based on platform + # @return [String] def initramfs_command if platform_family?("debian") "update-initramfs -u" @@ -94,6 +100,12 @@ class Chef "dracut -f" end end + + # see if the module is listed in /proc/modules or not + # @return [Boolean] + def module_loaded? + /^#{new_resource.modname}/.match?(::File.read("/proc/modules")) + end end end end |