Remove COMMAND_WARNINGS and warn (#77411)

* Remove COMMAND_WARNINGS and warn

Fixes #77394
pull/77417/head
Martin Krizek 2 years ago committed by GitHub
parent e080bae766
commit 6d260ad967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
removed_features:
- Remove deprecated ``COMMAND_WARNINGS`` configuration option (https://github.com/ansible/ansible/issues/77394)
- command/shell - remove deprecated ``warn`` module param

@ -134,8 +134,6 @@ and may see output like this:
fatal: [192.0.2.50]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.0.2.50 port 22: No route to host", "unreachable": true}
TASK [Leaving a mark] *******************************************************************************************************************
[WARNING]: Consider using the file module with state=touch rather than running 'touch'. If you need to use command because file is
insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.
changed: [aserver.example.org]
changed: [bserver.example.org]

@ -382,21 +382,6 @@ ACTION_WARNINGS:
- {key: action_warnings, section: defaults}
type: boolean
version_added: "2.5"
COMMAND_WARNINGS:
name: Command module warnings
default: False
description:
- Ansible can issue a warning when the shell or command module is used and the command appears to be similar to an existing Ansible module.
- These warnings can be silenced by adjusting this setting to False. You can also control this at the task level with the module option ``warn``.
- As of version 2.11, this is disabled by default.
env: [{name: ANSIBLE_COMMAND_WARNINGS}]
ini:
- {key: command_warnings, section: defaults}
type: boolean
version_added: "1.8"
deprecated:
why: the command warnings feature is being removed
version: "2.14"
LOCALHOST_WARNING:
name: Warning when using implicit inventory with only localhost
default: True

@ -72,14 +72,6 @@ options:
description:
- Change into this directory before running the command.
version_added: "0.6"
warn:
description:
- (deprecated) Enable or disable task warnings.
- This feature is deprecated and will be removed in 2.14.
- As of version 2.11, this option is now disabled by default.
type: bool
default: no
version_added: "1.8"
stdin:
description:
- Set the stdin of the command directly to the specified value.
@ -229,42 +221,6 @@ from ansible.module_utils._text import to_native, to_bytes, to_text
from ansible.module_utils.common.collections import is_iterable
def check_command(module, commandline):
arguments = {'chown': 'owner', 'chmod': 'mode', 'chgrp': 'group',
'ln': 'state=link', 'mkdir': 'state=directory',
'rmdir': 'state=absent', 'rm': 'state=absent', 'touch': 'state=touch'}
commands = {'curl': 'get_url or uri', 'wget': 'get_url or uri',
'svn': 'subversion', 'service': 'service',
'mount': 'mount', 'rpm': 'yum, dnf or zypper', 'yum': 'yum', 'apt-get': 'apt',
'tar': 'unarchive', 'unzip': 'unarchive', 'sed': 'replace, lineinfile or template',
'dnf': 'dnf', 'zypper': 'zypper'}
become = ['sudo', 'su', 'pbrun', 'pfexec', 'runas', 'pmrun', 'machinectl']
if isinstance(commandline, list):
command = commandline[0]
else:
command = commandline.split()[0]
command = os.path.basename(command)
disable_suffix = "If you need to use '{cmd}' because the {mod} module is insufficient you can add" \
" 'warn: false' to this command task or set 'command_warnings=False' in" \
" the defaults section of ansible.cfg to get rid of this message."
substitutions = {'mod': None, 'cmd': command}
if command in arguments:
msg = "Consider using the {mod} module with {subcmd} rather than running '{cmd}'. " + disable_suffix
substitutions['mod'] = 'file'
substitutions['subcmd'] = arguments[command]
module.warn(msg.format(**substitutions))
if command in commands:
msg = "Consider using the {mod} module rather than running '{cmd}'. " + disable_suffix
substitutions['mod'] = commands[command]
module.warn(msg.format(**substitutions))
if command in become:
module.warn("Consider using 'become', 'become_method', and 'become_user' rather than running %s" % (command,))
def main():
# the command module is the one ansible module that does not take key=value args
@ -280,7 +236,6 @@ def main():
creates=dict(type='path'),
removes=dict(type='path'),
# The default for this really comes from the action plugin
warn=dict(type='bool', default=False, removed_in_version='2.14', removed_from_collection='ansible.builtin'),
stdin=dict(required=False),
stdin_add_newline=dict(type='bool', default=True),
strip_empty_ends=dict(type='bool', default=True),
@ -294,7 +249,6 @@ def main():
argv = module.params['argv']
creates = module.params['creates']
removes = module.params['removes']
warn = module.params['warn']
stdin = module.params['stdin']
stdin_add_newline = module.params['stdin_add_newline']
strip = module.params['strip_empty_ends']
@ -325,9 +279,6 @@ def main():
args = [to_native(arg, errors='surrogate_or_strict', nonstring='simplerepr') for arg in args]
r['cmd'] = args
if warn:
# nany telling you to use module instead!
check_command(module, args)
if chdir:
chdir = to_bytes(chdir, errors='surrogate_or_strict')

@ -53,12 +53,6 @@ options:
- This expects an absolute path to the executable.
type: path
version_added: "0.9"
warn:
description:
- Whether to enable task warnings.
type: bool
default: yes
version_added: "1.8"
stdin:
description:
- Set the stdin of the command directly to the specified value.
@ -155,12 +149,6 @@ EXAMPLES = r'''
args:
executable: /usr/bin/expect
delegate_to: localhost
# Disabling warnings
- name: Using curl to connect to a host via SOCKS proxy (unsupported in uri). Ordinarily this would throw a warning
ansible.builtin.shell: curl --socks5 localhost:9000 http://www.ansible.com
args:
warn: no
'''
RETURN = r'''

@ -403,8 +403,6 @@ EXAMPLES = '''
# Handler showing how to clean yum metadata cache
- name: yum-clean-metadata
ansible.builtin.command: yum clean metadata
args:
warn: no
# Example removing a repository and cleaning up metadata cache
- name: Remove repository (and clean up left-over metadata)

@ -16,10 +16,6 @@ class ActionModule(ActionBase):
results = super(ActionModule, self).run(tmp, task_vars)
del tmp # tmp no longer has any effect
# Command module has a special config option to turn off the command nanny warnings
if 'warn' not in self._task.args and C.COMMAND_WARNINGS:
self._task.args['warn'] = C.COMMAND_WARNINGS
wrap_async = self._task.async_val and not self._connection.has_native_async
# explicitly call `ansible.legacy.command` for backcompat to allow library/ override of `command` while not allowing
# collections search for an unqualified `command` module

@ -59,8 +59,6 @@
- name: list the created tar contents
command: tar -tf {{ galaxy_dir }}/scratch/ansible_test/ignore/ansible_test-ignore-1.0.0.tar.gz
args:
warn: false
register: tar_output
- name: assert ignored files are not present in the archive

@ -461,45 +461,6 @@
path: "{{ remote_tmp_dir_test }}/afile.txt"
state: absent
- name: test warning with command
command:
cmd: "rm -h"
warn: yes
ignore_errors: yes
register: warn_result
- name: assert warning exists
assert:
that:
- warn_result.warnings | length == 1
- "'Consider using the file module with state=absent rather than running \\'rm\\'' in warn_result.warnings[0]"
- name: test warning with shell
shell: "sed -h"
args:
warn: yes
ignore_errors: yes
register: warn_result
- name: assert warning exists
assert:
that:
- warn_result.warnings | length == 1
- "'Consider using the replace, lineinfile or template module rather than running \\'sed\\'' in warn_result.warnings[0]"
- name: test become warning
command:
cmd: "sudo true"
warn: yes
ignore_errors: yes
register: warn_result
- name: assert warning exists
assert:
that:
- warn_result.warnings | length == 1
- "'Consider using \\'become\\', \\'become_method\\', and \\'become_user\\' rather than running sudo' in warn_result.warnings[0]"
- name: test check mode skip message
command:
cmd: "true"

@ -26,7 +26,6 @@
command: "ln -s '{{ item.value }}' '{{ item.key }}'"
args:
chdir: '{{role_path}}/files/subdir/subdir1'
warn: no
with_dict: "{{ symlinks }}"
delegate_to: localhost

@ -6,8 +6,6 @@
shell: rpm -q python2-dnf
register: rpm_result
ignore_errors: true
args:
warn: no
# Don't uninstall python2-dnf with the `dnf` module in case it needs to load
# some dnf python files after the package is uninstalled.

@ -68,7 +68,6 @@
- name: ARCHIVE | Inspect archive file
command:
cmd: "{{ git_list_commands[item] }} {{ checkout_dir }}/test_role.{{ item }}"
warn: no
register: archive_content
with_items: "{{ git_archive_extensions[ansible_os_family ~ ansible_distribution_major_version | default('default') ] | default(git_archive_extensions.default) }}"

@ -10,8 +10,6 @@
- name: Update cache
command: dnf makecache
args:
warn: no
- name: Install docker
dnf:

@ -14,8 +14,6 @@
- name: Enable extras repository for RHEL on AWS
# RHEL 7.6 uses REGION-rhel-server-extras and RHEL 7.7+ use rhel-7-server-rhui-extras-rpms
command: yum-config-manager --enable REGION-rhel-server-extras rhel-7-server-rhui-extras-rpms
args:
warn: no
# They broke their .repo file, so we set it up ourselves
- name: Set-up repository
@ -28,8 +26,6 @@
- name: Update cache
command: yum -y makecache fast
args:
warn: no
- name: Install docker
yum:

@ -32,8 +32,6 @@
- name: Find libfaketime path
shell: '{{ list_pkg_files }} {{ faketime_pkg }} | grep -F libfaketime.so.1'
args:
warn: false
register: libfaketime_path
when: list_pkg_files is defined

@ -3,5 +3,3 @@
- name: Uninstall Paramiko and crypto policies scripts using dnf history undo
command: dnf history undo last --assumeyes
args:
warn: no

@ -1,4 +1,2 @@
- name: Uninstall Paramiko using dnf history undo
command: dnf history undo last --assumeyes
args:
warn: no

@ -1,4 +1,2 @@
- name: Uninstall Paramiko using yum history undo
command: yum history undo last --assumeyes
args:
warn: no

@ -1,4 +1,2 @@
- name: Uninstall Paramiko for Python 2 using zypper
command: zypper --quiet --non-interactive remove --clean-deps python2-paramiko
args:
warn: no

@ -1,4 +1,2 @@
- name: Uninstall Paramiko for Python 3 using zypper
command: zypper --quiet --non-interactive remove --clean-deps python3-paramiko
args:
warn: no

@ -66,8 +66,6 @@
register: repolist
until: repolist.rc == 0
retries: 5
args:
warn: no
- name: ensure {{ yum_repository_test_repo.name }} was added
assert:

@ -333,7 +333,6 @@ lib/ansible/module_utils/compat/_selectors2.py mypy-3.9:assignment # vendored c
lib/ansible/module_utils/compat/_selectors2.py mypy-3.10:assignment # vendored code
lib/ansible/module_utils/compat/_selectors2.py mypy-2.7:attr-defined # vendored code
lib/ansible/modules/apt_key.py validate-modules:ansible-deprecated-version
lib/ansible/modules/command.py validate-modules:ansible-deprecated-version
lib/ansible/modules/get_url.py pylint:ansible-deprecated-version
lib/ansible/plugins/cache/__init__.py pylint:ansible-deprecated-version
lib/ansible/plugins/callback/default.py pylint:ansible-deprecated-version

Loading…
Cancel
Save