diff --git a/changelogs/fragments/remove-warnings-retval.yml b/changelogs/fragments/remove-warnings-retval.yml new file mode 100644 index 00000000000..aa887c021a7 --- /dev/null +++ b/changelogs/fragments/remove-warnings-retval.yml @@ -0,0 +1,2 @@ +minor_changes: + - "modules - use ``AnsibleModule.warn`` instead of passing ``warnings`` to ``exit_json`` or ``fail_json`` which is deprecated." diff --git a/lib/ansible/modules/assemble.py b/lib/ansible/modules/assemble.py index ff570aee1b9..35d435381e4 100644 --- a/lib/ansible/modules/assemble.py +++ b/lib/ansible/modules/assemble.py @@ -181,7 +181,7 @@ def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, igno return temp_path -def cleanup(path, result=None): +def cleanup(module, path, result=None): # cleanup just in case if os.path.exists(path): try: @@ -189,7 +189,7 @@ def cleanup(path, result=None): except (IOError, OSError) as e: # don't error on possible race conditions, but keep warning 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(): @@ -261,7 +261,7 @@ def main(): (rc, out, err) = module.run_command(validate % path) result['validation'] = dict(rc=rc, stdout=out, stderr=err) if rc != 0: - cleanup(path) + cleanup(module, path) module.fail_json(msg="failed to validate: rc:%s error:%s" % (rc, err)) if backup and dest_hash is not None: result['backup_file'] = module.backup_local(dest) @@ -269,7 +269,7 @@ def main(): module.atomic_move(path, dest, unsafe_writes=module.params['unsafe_writes']) changed = True - cleanup(path, result) + cleanup(module, path, result) # handle file permissions file_args = module.load_file_common_arguments(module.params) diff --git a/lib/ansible/modules/cron.py b/lib/ansible/modules/cron.py index 8abfca172fa..925004b83f2 100644 --- a/lib/ansible/modules/cron.py +++ b/lib/ansible/modules/cron.py @@ -618,7 +618,6 @@ def main(): changed = False res_args = dict() - warnings = list() if cron_file: @@ -627,8 +626,8 @@ def main(): cron_file_basename = os.path.basename(cron_file) 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 + - ' solely of upper- and lower-case letters, digits, underscores, and hyphens') + module.warn('Filename portion of cron_file ("%s") should consist' % cron_file_basename + + ' 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. os.umask(int('022', 8)) @@ -693,7 +692,7 @@ def main(): if do_install: for char in ['\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 job = crontab.get_cron_job(minute, hour, day, month, weekday, job, special_time, disabled) @@ -734,7 +733,6 @@ def main(): res_args = dict( jobs=crontab.get_jobnames(), envs=crontab.get_envnames(), - warnings=warnings, changed=changed ) diff --git a/lib/ansible/modules/git.py b/lib/ansible/modules/git.py index f7b5ae9752f..9c21466e6ab 100644 --- a/lib/ansible/modules/git.py +++ b/lib/ansible/modules/git.py @@ -317,11 +317,6 @@ remote_url_changed: returned: success type: bool 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: description: Contains the new path of .git directory if it is changed. returned: success @@ -1240,7 +1235,7 @@ def main(): archive_prefix = module.params['archive_prefix'] separate_git_dir = module.params['separate_git_dir'] - result = dict(changed=False, warnings=list()) + result = dict(changed=False) if module.params['accept_hostkey']: if ssh_opts is not None: diff --git a/lib/ansible/modules/pip.py b/lib/ansible/modules/pip.py index 2d520618f12..39e3457696a 100644 --- a/lib/ansible/modules/pip.py +++ b/lib/ansible/modules/pip.py @@ -814,10 +814,8 @@ def main(): elif requirements: cmd.extend(['-r', requirements]) else: - module.exit_json( - changed=False, - warnings=["No valid name or requirements file found."], - ) + module.warn("No valid name or requirements file found.") + module.exit_json(changed=False) if module.check_mode: if extra_args or requirements or state == 'latest' or not name: