mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
[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:
parent
e2573de08d
commit
7ac342e237
6 changed files with 21 additions and 28 deletions
6
changelogs/fragments/10459-deprecations.yml
Normal file
6
changelogs/fragments/10459-deprecations.yml
Normal 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)."
|
|
@ -164,12 +164,12 @@ def _module_is_enabled(module):
|
|||
if module.params['ignore_configcheck']:
|
||||
if 'AH00534' in stderr and 'mpm_' in module.params['name']:
|
||||
if module.params['warn_mpm_absent']:
|
||||
module.warnings.append(
|
||||
module.warn(
|
||||
"No MPM module loaded! apache2 reload AND other module actions"
|
||||
" will fail if no MPM module is loaded immediately."
|
||||
)
|
||||
else:
|
||||
module.warnings.append(error_msg)
|
||||
module.warn(error_msg)
|
||||
return False
|
||||
else:
|
||||
module.fail_json(msg=error_msg)
|
||||
|
@ -224,9 +224,7 @@ def _set_state(module, state):
|
|||
|
||||
if _module_is_enabled(module) != want_enabled:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True,
|
||||
result=success_msg,
|
||||
warnings=module.warnings)
|
||||
module.exit_json(changed=True, result=success_msg)
|
||||
|
||||
a2mod_binary_path = module.get_bin_path(a2mod_binary)
|
||||
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])
|
||||
|
||||
if _module_is_enabled(module) == want_enabled:
|
||||
module.exit_json(changed=True,
|
||||
result=success_msg,
|
||||
warnings=module.warnings)
|
||||
module.exit_json(changed=True, result=success_msg)
|
||||
else:
|
||||
msg = (
|
||||
'Failed to set module {name} to {state}:\n'
|
||||
|
@ -261,9 +257,7 @@ def _set_state(module, state):
|
|||
stdout=stdout,
|
||||
stderr=stderr)
|
||||
else:
|
||||
module.exit_json(changed=False,
|
||||
result=success_msg,
|
||||
warnings=module.warnings)
|
||||
module.exit_json(changed=False, result=success_msg)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -279,8 +273,6 @@ def main():
|
|||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
module.warnings = []
|
||||
|
||||
name = module.params['name']
|
||||
if name == 'cgi' and _run_threaded(module):
|
||||
module.fail_json(msg="Your MPM seems to be threaded. No automatic actions on module cgi possible.")
|
||||
|
|
|
@ -241,8 +241,8 @@ def main():
|
|||
(msg, changed) = present(path, username, password, hash_scheme, create, check_mode)
|
||||
elif state == 'absent':
|
||||
if not os.path.exists(path):
|
||||
module.exit_json(msg="%s not present" % username,
|
||||
warnings="%s does not exist" % path, changed=False)
|
||||
module.warn("%s does not exist" % path)
|
||||
module.exit_json(msg="%s not present" % username, changed=False)
|
||||
(msg, changed) = absent(path, username, check_mode)
|
||||
else:
|
||||
module.fail_json(msg="Invalid state: %s" % state)
|
||||
|
|
|
@ -103,7 +103,6 @@ def syspatch_run(module):
|
|||
cmd = module.get_bin_path('syspatch', True)
|
||||
changed = False
|
||||
reboot_needed = False
|
||||
warnings = []
|
||||
|
||||
# Set safe defaults for run_flag and check_flag
|
||||
run_flag = ['-c']
|
||||
|
@ -145,11 +144,11 @@ def syspatch_run(module):
|
|||
# Kernel update applied
|
||||
reboot_needed = True
|
||||
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 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
|
||||
else:
|
||||
|
@ -161,7 +160,6 @@ def syspatch_run(module):
|
|||
rc=rc,
|
||||
stderr=err,
|
||||
stdout=out,
|
||||
warnings=warnings
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -102,7 +102,6 @@ def sysupgrade_run(module):
|
|||
sysupgrade_bin = module.get_bin_path('/usr/sbin/sysupgrade', required=True)
|
||||
cmd = [sysupgrade_bin]
|
||||
changed = False
|
||||
warnings = []
|
||||
|
||||
# Setup command flags
|
||||
if module.params['snapshot']:
|
||||
|
@ -138,7 +137,6 @@ def sysupgrade_run(module):
|
|||
rc=rc,
|
||||
stderr=err,
|
||||
stdout=out,
|
||||
warnings=warnings
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -250,7 +250,7 @@ def repo_exists(module, repodata, overwrite_multiple):
|
|||
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."
|
||||
repo = repodata['url']
|
||||
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'):
|
||||
cmd.extend(['--priority', str(repodata['priority'])])
|
||||
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':
|
||||
cmd.append('--disable')
|
||||
|
@ -277,7 +277,7 @@ def addmodify_repo(module, repodata, old_repos, zypper_version, warnings):
|
|||
else:
|
||||
cmd.append('--no-gpgcheck')
|
||||
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':
|
||||
cmd.append('--refresh')
|
||||
|
@ -350,7 +350,6 @@ def main():
|
|||
runrefresh = module.params['runrefresh']
|
||||
|
||||
zypper_version = get_zypper_version(module)
|
||||
warnings = [] # collect warning messages for final output
|
||||
|
||||
repodata = {
|
||||
'url': repo,
|
||||
|
@ -460,7 +459,7 @@ def main():
|
|||
if runrefresh:
|
||||
runrefreshrepo(module, auto_import_keys, shortname)
|
||||
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):
|
||||
runrefreshrepo(module, auto_import_keys, shortname)
|
||||
elif state == 'absent':
|
||||
|
@ -469,9 +468,9 @@ def main():
|
|||
rc, stdout, stderr = remove_repo(module, shortname)
|
||||
|
||||
if rc == 0:
|
||||
module.exit_json(changed=True, repodata=repodata, state=state, warnings=warnings)
|
||||
module.exit_json(changed=True, repodata=repodata, state=state)
|
||||
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__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue