1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

modprobe: Avoid FileNotFoundError when directories don't exist. (#8005)

* Avoid FileNotFoundError when directories don't exist.

* Adds changelog fragment.

* Update changelogs/fragments/7717-prevent-modprobe-error.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Nate Douglas 2024-02-25 01:38:22 -05:00 committed by GitHub
parent 638a7fc199
commit e0dbe9c98d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- modprobe - listing modules files or modprobe files could trigger a FileNotFoundError if ``/etc/modprobe.d`` or ``/etc/modules-load.d`` did not exist. Relevant functions now return empty lists if the directories do not exist to avoid crashing the module (https://github.com/ansible-collections/community.general/issues/7717).

View file

@ -232,12 +232,16 @@ class Modprobe(object):
@property
def modules_files(self):
if not os.path.isdir(MODULES_LOAD_LOCATION):
return []
modules_paths = [os.path.join(MODULES_LOAD_LOCATION, path)
for path in os.listdir(MODULES_LOAD_LOCATION)]
return [path for path in modules_paths if os.path.isfile(path)]
@property
def modprobe_files(self):
if not os.path.isdir(PARAMETERS_FILES_LOCATION):
return []
modules_paths = [os.path.join(PARAMETERS_FILES_LOCATION, path)
for path in os.listdir(PARAMETERS_FILES_LOCATION)]
return [path for path in modules_paths if os.path.isfile(path)]