[PR #9052/d0b4e91c backport][stable-8] modprobe: fix --check mode not being honored for persistent option (#9070)

modprobe: fix --check mode not being honored for persistent option (#9052)

* modprobe: fix --check mode not being honored for persistent option

* Add CHANGELOG

* Update CHANGELOG

* Update changelogs/fragments/9052-modprobe-bugfix.yml

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

---------

Co-authored-by: d-usuba <d-usuba@sakura.ad.jp>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit d0b4e91cac)

Co-authored-by: salmon111 <campfire@kumachans.net>
pull/9088/head
patchback[bot] 2024-10-28 21:25:13 +01:00 committed by GitHub
parent 5cddc4d617
commit becc6c7200
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- modprobe - fix check mode not being honored for ``persistent`` option (https://github.com/ansible-collections/community.general/issues/9051, https://github.com/ansible-collections/community.general/pull/9052).

View File

@ -163,8 +163,9 @@ class Modprobe(object):
def create_module_file(self):
file_path = os.path.join(MODULES_LOAD_LOCATION,
self.name + '.conf')
with open(file_path, 'w') as file:
file.write(self.name + '\n')
if not self.check_mode:
with open(file_path, 'w') as file:
file.write(self.name + '\n')
@property
def module_options_file_content(self):
@ -175,8 +176,9 @@ class Modprobe(object):
def create_module_options_file(self):
new_file_path = os.path.join(PARAMETERS_FILES_LOCATION,
self.name + '.conf')
with open(new_file_path, 'w') as file:
file.write(self.module_options_file_content)
if not self.check_mode:
with open(new_file_path, 'w') as file:
file.write(self.module_options_file_content)
def disable_old_params(self):
@ -190,7 +192,7 @@ class Modprobe(object):
file_content[index] = '#' + line
content_changed = True
if content_changed:
if not self.check_mode and content_changed:
with open(modprobe_file, 'w') as file:
file.write('\n'.join(file_content))
@ -206,7 +208,7 @@ class Modprobe(object):
file_content[index] = '#' + line
content_changed = True
if content_changed:
if not self.check_mode and content_changed:
with open(module_file, 'w') as file:
file.write('\n'.join(file_content))