Passing warnings to exit/fail_json is deprecated. (#85109)

pull/85114/head
Martin Krizek 7 months ago committed by GitHub
parent 7e00053a30
commit 8b9ddf5544
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
minor_changes:
- "modules - use ``AnsibleModule.warn`` instead of passing ``warnings`` to ``exit_json`` or ``fail_json`` which is deprecated."

@ -181,7 +181,7 @@ def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, igno
return temp_path return temp_path
def cleanup(path, result=None): def cleanup(module, path, result=None):
# cleanup just in case # cleanup just in case
if os.path.exists(path): if os.path.exists(path):
try: try:
@ -189,7 +189,7 @@ def cleanup(path, result=None):
except (IOError, OSError) as e: except (IOError, OSError) as e:
# don't error on possible race conditions, but keep warning # don't error on possible race conditions, but keep warning
if result is not None: if result is not None:
result['warnings'] = ['Unable to remove temp file (%s): %s' % (path, to_native(e))] module.warn('Unable to remove temp file (%s): %s' % (path, to_native(e)))
def main(): def main():
@ -261,7 +261,7 @@ def main():
(rc, out, err) = module.run_command(validate % path) (rc, out, err) = module.run_command(validate % path)
result['validation'] = dict(rc=rc, stdout=out, stderr=err) result['validation'] = dict(rc=rc, stdout=out, stderr=err)
if rc != 0: if rc != 0:
cleanup(path) cleanup(module, path)
module.fail_json(msg="failed to validate: rc:%s error:%s" % (rc, err)) module.fail_json(msg="failed to validate: rc:%s error:%s" % (rc, err))
if backup and dest_hash is not None: if backup and dest_hash is not None:
result['backup_file'] = module.backup_local(dest) result['backup_file'] = module.backup_local(dest)
@ -269,7 +269,7 @@ def main():
module.atomic_move(path, dest, unsafe_writes=module.params['unsafe_writes']) module.atomic_move(path, dest, unsafe_writes=module.params['unsafe_writes'])
changed = True changed = True
cleanup(path, result) cleanup(module, path, result)
# handle file permissions # handle file permissions
file_args = module.load_file_common_arguments(module.params) file_args = module.load_file_common_arguments(module.params)

@ -618,7 +618,6 @@ def main():
changed = False changed = False
res_args = dict() res_args = dict()
warnings = list()
if cron_file: if cron_file:
@ -627,7 +626,7 @@ def main():
cron_file_basename = os.path.basename(cron_file) cron_file_basename = os.path.basename(cron_file)
if not re.search(r'^[A-Z0-9_-]+$', cron_file_basename, re.I): if not re.search(r'^[A-Z0-9_-]+$', cron_file_basename, re.I):
warnings.append('Filename portion of cron_file ("%s") should consist' % cron_file_basename + module.warn('Filename portion of cron_file ("%s") should consist' % cron_file_basename +
' solely of upper- and lower-case letters, digits, underscores, and hyphens') ' solely of upper- and lower-case letters, digits, underscores, and hyphens')
# Ensure all files generated are only writable by the owning user. Primarily relevant for the cron_file option. # Ensure all files generated are only writable by the owning user. Primarily relevant for the cron_file option.
@ -693,7 +692,7 @@ def main():
if do_install: if do_install:
for char in ['\r', '\n']: for char in ['\r', '\n']:
if char in job.strip('\r\n'): if char in job.strip('\r\n'):
warnings.append('Job should not contain line breaks') module.warn('Job should not contain line breaks')
break break
job = crontab.get_cron_job(minute, hour, day, month, weekday, job, special_time, disabled) job = crontab.get_cron_job(minute, hour, day, month, weekday, job, special_time, disabled)
@ -734,7 +733,6 @@ def main():
res_args = dict( res_args = dict(
jobs=crontab.get_jobnames(), jobs=crontab.get_jobnames(),
envs=crontab.get_envnames(), envs=crontab.get_envnames(),
warnings=warnings,
changed=changed changed=changed
) )

@ -317,11 +317,6 @@ remote_url_changed:
returned: success returned: success
type: bool type: bool
sample: True sample: True
warnings:
description: List of warnings if requested features were not available due to a too old git version.
returned: error
type: str
sample: git version is too old to fully support the depth argument. Falling back to full checkouts.
git_dir_now: git_dir_now:
description: Contains the new path of .git directory if it is changed. description: Contains the new path of .git directory if it is changed.
returned: success returned: success
@ -1240,7 +1235,7 @@ def main():
archive_prefix = module.params['archive_prefix'] archive_prefix = module.params['archive_prefix']
separate_git_dir = module.params['separate_git_dir'] separate_git_dir = module.params['separate_git_dir']
result = dict(changed=False, warnings=list()) result = dict(changed=False)
if module.params['accept_hostkey']: if module.params['accept_hostkey']:
if ssh_opts is not None: if ssh_opts is not None:

@ -814,10 +814,8 @@ def main():
elif requirements: elif requirements:
cmd.extend(['-r', requirements]) cmd.extend(['-r', requirements])
else: else:
module.exit_json( module.warn("No valid name or requirements file found.")
changed=False, module.exit_json(changed=False)
warnings=["No valid name or requirements file found."],
)
if module.check_mode: if module.check_mode:
if extra_args or requirements or state == 'latest' or not name: if extra_args or requirements or state == 'latest' or not name:

Loading…
Cancel
Save