From 2c1172d5d2c791afbad7bc55cbc8a1d746b46f76 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:27:38 +0100 Subject: [PATCH] [PR #9052/d0b4e91c backport][stable-7] modprobe: fix --check mode not being honored for persistent option (#9069) 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 --------- Co-authored-by: d-usuba Co-authored-by: Felix Fontein (cherry picked from commit d0b4e91cac95b2b3c0984704799b1f1f2d4ce8b8) Co-authored-by: salmon111 --- changelogs/fragments/9052-modprobe-bugfix.yml | 2 ++ plugins/modules/modprobe.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/9052-modprobe-bugfix.yml diff --git a/changelogs/fragments/9052-modprobe-bugfix.yml b/changelogs/fragments/9052-modprobe-bugfix.yml new file mode 100644 index 0000000000..b9519e9055 --- /dev/null +++ b/changelogs/fragments/9052-modprobe-bugfix.yml @@ -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). diff --git a/plugins/modules/modprobe.py b/plugins/modules/modprobe.py index f271b3946f..57e682245f 100644 --- a/plugins/modules/modprobe.py +++ b/plugins/modules/modprobe.py @@ -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))