-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load modules config only for modules managed by puppet
- Loading branch information
Showing
1 changed file
with
61 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
# @summary Return a hash of loaded kernel modules | ||
# @summary Return a hash of loaded kernel modules explicitly declared by puppet | ||
# e.g. using kmod::load { 'overlay': } | ||
|
||
Facter.add(:kmods) do | ||
confine kernel: :linux | ||
def kmod_load_module_config(kmodule) | ||
if File.exist?('/sys/module') | ||
config = { | ||
'parameters' => {}, | ||
'used_by' => [], | ||
} | ||
|
||
kmod = {} | ||
if File.directory?("/sys/module/#{kmodule}/parameters") | ||
Dir.foreach("/sys/module/#{kmodule}/parameters") do |param| | ||
next if ['.', '..'].include?(param) | ||
|
||
setcode do | ||
if File.exist?('/sys/module') | ||
Dir.foreach('/sys/module') do |directory| | ||
next if ['.', '..'].include?(directory) | ||
|
||
kmod[directory] = { | ||
'parameters' => {}, | ||
'used_by' => [], | ||
} | ||
|
||
if File.directory?("/sys/module/#{directory}/parameters") | ||
Dir.foreach("/sys/module/#{directory}/parameters") do |param| | ||
next if ['.', '..'].include?(param) | ||
|
||
next unless File.readable?("/sys/module/#{directory}/parameters/#{param}") | ||
|
||
begin | ||
kmod[directory]['parameters'][param] = File.read("/sys/module/#{directory}/parameters/#{param}").chomp | ||
rescue StandardError | ||
# some kernel parameters are write only | ||
# even though they have the read bit set | ||
# so just ignore read errors | ||
nil | ||
end | ||
next unless File.readable?("/sys/module/#{kmodule}/parameters/#{param}") | ||
|
||
begin | ||
config['parameters'][param] = File.read("/sys/module/#{kmodule}/parameters/#{param}").chomp | ||
rescue StandardError | ||
# some kernel parameters are write only | ||
# even though they have the read bit set | ||
# so just ignore read errors | ||
nil | ||
end | ||
end | ||
end | ||
|
||
if File.directory?("/sys/module/#{directory}/holders") | ||
Dir.foreach("/sys/module/#{directory}/holders") do |used| | ||
next if ['.', '..'].include?(used) | ||
if File.directory?("/sys/module/#{kmodule}/holders") | ||
Dir.foreach("/sys/module/#{kmodule}/holders") do |used| | ||
next if ['.', '..'].include?(used) | ||
|
||
kmod[directory]['used_by'] << used | ||
end | ||
config['used_by'] << used | ||
end | ||
end | ||
|
||
kmod | ||
else | ||
Facter.debug('/sys/module is not found. skipping.') | ||
config | ||
else | ||
Facter.debug('/sys/module is not found. skipping.') | ||
end | ||
end | ||
|
||
Facter.add(:kmods) do | ||
confine :osfamily => %w{Debian} | ||
|
||
kmod = {} | ||
|
||
setcode do | ||
Dir.foreach('/etc/modules-load.d') do |item| | ||
next if ['.', '..', 'modules.conf'].include?(item) | ||
if item.end_with? '.conf' | ||
config = item[0...-5] | ||
kmod[config] = kmod_load_module_config(config) | ||
end | ||
end | ||
kmod | ||
end | ||
end | ||
|
||
Facter.add(:kmods) do | ||
confine :osfamily => %w{RedHat} | ||
|
||
kmod = {} | ||
|
||
setcode do | ||
Dir.foreach('/etc/sysconfig/modules') do |item| | ||
next if ['.', '..'].include?(item) | ||
if item.end_with? '.modules' | ||
config = item[0...-8] | ||
kmod[config] = kmod_load_module_config(config) | ||
end | ||
end | ||
kmod | ||
end | ||
end |