voxpupuli / puppet-kmod

manage kernel module with puppet
Apache License 2.0
17 stars 63 forks source link

Hide read error on params when you can't read them #78

Closed jcpunk closed 2 years ago

jcpunk commented 2 years ago

Pull Request (PR) description

This should keep from showing errors on params that are write only.

This Pull Request (PR) fixes the following issues

None listed

kenyon commented 2 years ago

Still getting the permission denied warning:

kenyon@beta ~ % sudo puppet agent --test
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/opt/puppetlabs/puppet/cache/lib/facter/kmod.rb]/content: 
--- /opt/puppetlabs/puppet/cache/lib/facter/kmod.rb     2022-02-02 17:58:56.180765273 -0800
+++ /tmp/puppet-file20220203-2601855-1i8wwif    2022-02-03 11:30:26.940804768 -0800
@@ -20,7 +20,7 @@
             Dir.foreach("/sys/module/#{directory}/parameters") do |param|
               next if ['.', '..'].include?(param)

-              kmod[directory]['parameters'][param] = File.read("/sys/module/#{directory}/parameters/#{param}").chomp
+              File.readable?("/sys/module/#{directory}/parameters/#{param}") && kmod[directory]['parameters'][param] = File.read("/sys/module/#{directory}/parameters/#{param}").chomp
             end
           rescue StandardError => e
             Facter.warn(e)

Notice: /File[/opt/puppetlabs/puppet/cache/lib/facter/kmod.rb]/content: content changed '{sha256}fe381dbb71ff5b063831169603b60d4bae91633880b5507ff5ff3c7b2170e8c8' to '{sha256}5f8358eb3c933fce630fe4bad46420ed123a25e669e9e332f26d2b10f530fbef'
Info: Loading facts
Warning: Facter: Permission denied @ rb_sysopen - /sys/module/md_mod/parameters/new_array
Info: Caching catalog for beta.kenyonralph.com
Info: Applying configuration version '4e0655397e4b0277f9827a063b07e06f57ea44c0'
Notice: Applied catalog in 15.38 seconds

Not sure where it's coming from. Would be nice if the warning could give a line number.

jcpunk commented 2 years ago

I'm showing that file as write only:

ls -l /sys/module/md_mod/parameters/new_array
--w-------. 1 root root 4096 Feb  3 13:53 /sys/module/md_mod/parameters/new_array

What does it look like on your system?

jcpunk commented 2 years ago

Pushed up a new version to try and do better....

kenyon commented 2 years ago

Same, /sys/module/md_mod/parameters/new_array is write only.

kenyon commented 2 years ago

No more warnings with commit ba9c4ac542df4a6c3548ccc4874e8a942b9bfb91. 👍

I can see the warning when running puppet agent --test --debug, but that's fine.