[PR #9052/d0b4e91c backport][stable-9] modprobe: fix --check mode not being honored for persistent option (#9071)
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/9078/head
parent
e5ab4be82d
commit
772b5b1ad3
|
@ -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).
|
|
@ -163,8 +163,9 @@ class Modprobe(object):
|
||||||
def create_module_file(self):
|
def create_module_file(self):
|
||||||
file_path = os.path.join(MODULES_LOAD_LOCATION,
|
file_path = os.path.join(MODULES_LOAD_LOCATION,
|
||||||
self.name + '.conf')
|
self.name + '.conf')
|
||||||
with open(file_path, 'w') as file:
|
if not self.check_mode:
|
||||||
file.write(self.name + '\n')
|
with open(file_path, 'w') as file:
|
||||||
|
file.write(self.name + '\n')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def module_options_file_content(self):
|
def module_options_file_content(self):
|
||||||
|
@ -175,8 +176,9 @@ class Modprobe(object):
|
||||||
def create_module_options_file(self):
|
def create_module_options_file(self):
|
||||||
new_file_path = os.path.join(PARAMETERS_FILES_LOCATION,
|
new_file_path = os.path.join(PARAMETERS_FILES_LOCATION,
|
||||||
self.name + '.conf')
|
self.name + '.conf')
|
||||||
with open(new_file_path, 'w') as file:
|
if not self.check_mode:
|
||||||
file.write(self.module_options_file_content)
|
with open(new_file_path, 'w') as file:
|
||||||
|
file.write(self.module_options_file_content)
|
||||||
|
|
||||||
def disable_old_params(self):
|
def disable_old_params(self):
|
||||||
|
|
||||||
|
@ -190,7 +192,7 @@ class Modprobe(object):
|
||||||
file_content[index] = '#' + line
|
file_content[index] = '#' + line
|
||||||
content_changed = True
|
content_changed = True
|
||||||
|
|
||||||
if content_changed:
|
if not self.check_mode and content_changed:
|
||||||
with open(modprobe_file, 'w') as file:
|
with open(modprobe_file, 'w') as file:
|
||||||
file.write('\n'.join(file_content))
|
file.write('\n'.join(file_content))
|
||||||
|
|
||||||
|
@ -206,7 +208,7 @@ class Modprobe(object):
|
||||||
file_content[index] = '#' + line
|
file_content[index] = '#' + line
|
||||||
content_changed = True
|
content_changed = True
|
||||||
|
|
||||||
if content_changed:
|
if not self.check_mode and content_changed:
|
||||||
with open(module_file, 'w') as file:
|
with open(module_file, 'w') as file:
|
||||||
file.write('\n'.join(file_content))
|
file.write('\n'.join(file_content))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue