[PR #10459/ee783066 backport][stable-10] Fix ansible-core 2.19 deprecations (#10470)

Fix ansible-core 2.19 deprecations (#10459)

Do not return warnings.

(cherry picked from commit ee7830667a)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-07-27 12:13:38 +02:00 committed by GitHub
commit 7ac342e237
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 21 additions and 28 deletions

View file

@ -0,0 +1,6 @@
bugfixes:
- "apache2_module - avoid ansible-core 2.19 deprecation (https://github.com/ansible-collections/community.general/pull/10459)."
- "htpasswd - avoid ansible-core 2.19 deprecation (https://github.com/ansible-collections/community.general/pull/10459)."
- "syspatch - avoid ansible-core 2.19 deprecation (https://github.com/ansible-collections/community.general/pull/10459)."
- "sysupgrade - avoid ansible-core 2.19 deprecation (https://github.com/ansible-collections/community.general/pull/10459)."
- "zypper_repository - avoid ansible-core 2.19 deprecation (https://github.com/ansible-collections/community.general/pull/10459)."

View file

@ -164,12 +164,12 @@ def _module_is_enabled(module):
if module.params['ignore_configcheck']: if module.params['ignore_configcheck']:
if 'AH00534' in stderr and 'mpm_' in module.params['name']: if 'AH00534' in stderr and 'mpm_' in module.params['name']:
if module.params['warn_mpm_absent']: if module.params['warn_mpm_absent']:
module.warnings.append( module.warn(
"No MPM module loaded! apache2 reload AND other module actions" "No MPM module loaded! apache2 reload AND other module actions"
" will fail if no MPM module is loaded immediately." " will fail if no MPM module is loaded immediately."
) )
else: else:
module.warnings.append(error_msg) module.warn(error_msg)
return False return False
else: else:
module.fail_json(msg=error_msg) module.fail_json(msg=error_msg)
@ -224,9 +224,7 @@ def _set_state(module, state):
if _module_is_enabled(module) != want_enabled: if _module_is_enabled(module) != want_enabled:
if module.check_mode: if module.check_mode:
module.exit_json(changed=True, module.exit_json(changed=True, result=success_msg)
result=success_msg,
warnings=module.warnings)
a2mod_binary_path = module.get_bin_path(a2mod_binary) a2mod_binary_path = module.get_bin_path(a2mod_binary)
if a2mod_binary_path is None: if a2mod_binary_path is None:
@ -241,9 +239,7 @@ def _set_state(module, state):
result, stdout, stderr = module.run_command(a2mod_binary_cmd + [name]) result, stdout, stderr = module.run_command(a2mod_binary_cmd + [name])
if _module_is_enabled(module) == want_enabled: if _module_is_enabled(module) == want_enabled:
module.exit_json(changed=True, module.exit_json(changed=True, result=success_msg)
result=success_msg,
warnings=module.warnings)
else: else:
msg = ( msg = (
'Failed to set module {name} to {state}:\n' 'Failed to set module {name} to {state}:\n'
@ -261,9 +257,7 @@ def _set_state(module, state):
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
else: else:
module.exit_json(changed=False, module.exit_json(changed=False, result=success_msg)
result=success_msg,
warnings=module.warnings)
def main(): def main():
@ -279,8 +273,6 @@ def main():
supports_check_mode=True, supports_check_mode=True,
) )
module.warnings = []
name = module.params['name'] name = module.params['name']
if name == 'cgi' and _run_threaded(module): if name == 'cgi' and _run_threaded(module):
module.fail_json(msg="Your MPM seems to be threaded. No automatic actions on module cgi possible.") module.fail_json(msg="Your MPM seems to be threaded. No automatic actions on module cgi possible.")

View file

@ -241,8 +241,8 @@ def main():
(msg, changed) = present(path, username, password, hash_scheme, create, check_mode) (msg, changed) = present(path, username, password, hash_scheme, create, check_mode)
elif state == 'absent': elif state == 'absent':
if not os.path.exists(path): if not os.path.exists(path):
module.exit_json(msg="%s not present" % username, module.warn("%s does not exist" % path)
warnings="%s does not exist" % path, changed=False) module.exit_json(msg="%s not present" % username, changed=False)
(msg, changed) = absent(path, username, check_mode) (msg, changed) = absent(path, username, check_mode)
else: else:
module.fail_json(msg="Invalid state: %s" % state) module.fail_json(msg="Invalid state: %s" % state)

View file

@ -103,7 +103,6 @@ def syspatch_run(module):
cmd = module.get_bin_path('syspatch', True) cmd = module.get_bin_path('syspatch', True)
changed = False changed = False
reboot_needed = False reboot_needed = False
warnings = []
# Set safe defaults for run_flag and check_flag # Set safe defaults for run_flag and check_flag
run_flag = ['-c'] run_flag = ['-c']
@ -145,11 +144,11 @@ def syspatch_run(module):
# Kernel update applied # Kernel update applied
reboot_needed = True reboot_needed = True
elif out.lower().find('syspatch updated itself') >= 0: elif out.lower().find('syspatch updated itself') >= 0:
warnings.append('Syspatch was updated. Please run syspatch again.') module.warn('Syspatch was updated. Please run syspatch again.')
# If no stdout, then warn user # If no stdout, then warn user
if len(out) == 0: if len(out) == 0:
warnings.append('syspatch had suggested changes, but stdout was empty.') module.warn('syspatch had suggested changes, but stdout was empty.')
changed = True changed = True
else: else:
@ -161,7 +160,6 @@ def syspatch_run(module):
rc=rc, rc=rc,
stderr=err, stderr=err,
stdout=out, stdout=out,
warnings=warnings
) )

View file

@ -102,7 +102,6 @@ def sysupgrade_run(module):
sysupgrade_bin = module.get_bin_path('/usr/sbin/sysupgrade', required=True) sysupgrade_bin = module.get_bin_path('/usr/sbin/sysupgrade', required=True)
cmd = [sysupgrade_bin] cmd = [sysupgrade_bin]
changed = False changed = False
warnings = []
# Setup command flags # Setup command flags
if module.params['snapshot']: if module.params['snapshot']:
@ -138,7 +137,6 @@ def sysupgrade_run(module):
rc=rc, rc=rc,
stderr=err, stderr=err,
stdout=out, stdout=out,
warnings=warnings
) )

View file

@ -250,7 +250,7 @@ def repo_exists(module, repodata, overwrite_multiple):
module.fail_json(msg=errmsg) module.fail_json(msg=errmsg)
def addmodify_repo(module, repodata, old_repos, zypper_version, warnings): def addmodify_repo(module, repodata, old_repos, zypper_version):
"Adds the repo, removes old repos before, that would conflict." "Adds the repo, removes old repos before, that would conflict."
repo = repodata['url'] repo = repodata['url']
cmd = _get_cmd(module, 'addrepo', '--check') cmd = _get_cmd(module, 'addrepo', '--check')
@ -263,7 +263,7 @@ def addmodify_repo(module, repodata, old_repos, zypper_version, warnings):
if zypper_version >= LooseVersion('1.12.25'): if zypper_version >= LooseVersion('1.12.25'):
cmd.extend(['--priority', str(repodata['priority'])]) cmd.extend(['--priority', str(repodata['priority'])])
else: else:
warnings.append("Setting priority only available for zypper >= 1.12.25. Ignoring priority argument.") module.warn("Setting priority only available for zypper >= 1.12.25. Ignoring priority argument.")
if repodata['enabled'] == '0': if repodata['enabled'] == '0':
cmd.append('--disable') cmd.append('--disable')
@ -277,7 +277,7 @@ def addmodify_repo(module, repodata, old_repos, zypper_version, warnings):
else: else:
cmd.append('--no-gpgcheck') cmd.append('--no-gpgcheck')
else: else:
warnings.append("Enabling/disabling gpgcheck only available for zypper >= 1.6.2. Using zypper default value.") module.warn("Enabling/disabling gpgcheck only available for zypper >= 1.6.2. Using zypper default value.")
if repodata['autorefresh'] == '1': if repodata['autorefresh'] == '1':
cmd.append('--refresh') cmd.append('--refresh')
@ -350,7 +350,6 @@ def main():
runrefresh = module.params['runrefresh'] runrefresh = module.params['runrefresh']
zypper_version = get_zypper_version(module) zypper_version = get_zypper_version(module)
warnings = [] # collect warning messages for final output
repodata = { repodata = {
'url': repo, 'url': repo,
@ -460,7 +459,7 @@ def main():
if runrefresh: if runrefresh:
runrefreshrepo(module, auto_import_keys, shortname) runrefreshrepo(module, auto_import_keys, shortname)
exit_unchanged() exit_unchanged()
rc, stdout, stderr = addmodify_repo(module, repodata, old_repos, zypper_version, warnings) rc, stdout, stderr = addmodify_repo(module, repodata, old_repos, zypper_version)
if rc == 0 and (runrefresh or auto_import_keys): if rc == 0 and (runrefresh or auto_import_keys):
runrefreshrepo(module, auto_import_keys, shortname) runrefreshrepo(module, auto_import_keys, shortname)
elif state == 'absent': elif state == 'absent':
@ -469,9 +468,9 @@ def main():
rc, stdout, stderr = remove_repo(module, shortname) rc, stdout, stderr = remove_repo(module, shortname)
if rc == 0: if rc == 0:
module.exit_json(changed=True, repodata=repodata, state=state, warnings=warnings) module.exit_json(changed=True, repodata=repodata, state=state)
else: else:
module.fail_json(msg="Zypper failed with rc %s" % rc, rc=rc, stdout=stdout, stderr=stderr, repodata=repodata, state=state, warnings=warnings) module.fail_json(msg="Zypper failed with rc %s" % rc, rc=rc, stdout=stdout, stderr=stderr, repodata=repodata, state=state)
if __name__ == '__main__': if __name__ == '__main__':