diff --git a/changelogs/fragments/77394-remove-command_warnings.yml b/changelogs/fragments/77394-remove-command_warnings.yml new file mode 100644 index 00000000000..5582bb3a039 --- /dev/null +++ b/changelogs/fragments/77394-remove-command_warnings.yml @@ -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 diff --git a/docs/docsite/rst/user_guide/intro_getting_started.rst b/docs/docsite/rst/user_guide/intro_getting_started.rst index bee9565ba84..641e25ad8f3 100644 --- a/docs/docsite/rst/user_guide/intro_getting_started.rst +++ b/docs/docsite/rst/user_guide/intro_getting_started.rst @@ -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] diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index c8d44598348..bc3367744db 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -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 diff --git a/lib/ansible/modules/command.py b/lib/ansible/modules/command.py index ebde2a249fc..ecf4d0f6c5a 100644 --- a/lib/ansible/modules/command.py +++ b/lib/ansible/modules/command.py @@ -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') diff --git a/lib/ansible/modules/shell.py b/lib/ansible/modules/shell.py index 6a6f9543f9c..52fda1b0159 100644 --- a/lib/ansible/modules/shell.py +++ b/lib/ansible/modules/shell.py @@ -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''' diff --git a/lib/ansible/modules/yum_repository.py b/lib/ansible/modules/yum_repository.py index fed1e4bc81b..119ce3071e8 100644 --- a/lib/ansible/modules/yum_repository.py +++ b/lib/ansible/modules/yum_repository.py @@ -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) diff --git a/lib/ansible/plugins/action/command.py b/lib/ansible/plugins/action/command.py index f267eb737f9..82a85dcd33a 100644 --- a/lib/ansible/plugins/action/command.py +++ b/lib/ansible/plugins/action/command.py @@ -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 diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/build.yml b/test/integration/targets/ansible-galaxy-collection/tasks/build.yml index 7e4a5ed65dd..8140d468a3c 100644 --- a/test/integration/targets/ansible-galaxy-collection/tasks/build.yml +++ b/test/integration/targets/ansible-galaxy-collection/tasks/build.yml @@ -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 diff --git a/test/integration/targets/command_shell/tasks/main.yml b/test/integration/targets/command_shell/tasks/main.yml index 031c5f4bca0..12a944c48c3 100644 --- a/test/integration/targets/command_shell/tasks/main.yml +++ b/test/integration/targets/command_shell/tasks/main.yml @@ -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" diff --git a/test/integration/targets/copy/tasks/main.yml b/test/integration/targets/copy/tasks/main.yml index a5211de1bd0..817fe0a17dc 100644 --- a/test/integration/targets/copy/tasks/main.yml +++ b/test/integration/targets/copy/tasks/main.yml @@ -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 diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml index 22e2fb154bf..ec1c36f8603 100644 --- a/test/integration/targets/dnf/tasks/dnf.yml +++ b/test/integration/targets/dnf/tasks/dnf.yml @@ -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. diff --git a/test/integration/targets/git/tasks/archive.yml b/test/integration/targets/git/tasks/archive.yml index 952154dcacc..588148d570c 100644 --- a/test/integration/targets/git/tasks/archive.yml +++ b/test/integration/targets/git/tasks/archive.yml @@ -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) }}" diff --git a/test/integration/targets/incidental_setup_docker/tasks/Fedora.yml b/test/integration/targets/incidental_setup_docker/tasks/Fedora.yml index 9f52e8f1441..ff5e665d81b 100644 --- a/test/integration/targets/incidental_setup_docker/tasks/Fedora.yml +++ b/test/integration/targets/incidental_setup_docker/tasks/Fedora.yml @@ -10,8 +10,6 @@ - name: Update cache command: dnf makecache - args: - warn: no - name: Install docker dnf: diff --git a/test/integration/targets/incidental_setup_docker/tasks/RedHat-7.yml b/test/integration/targets/incidental_setup_docker/tasks/RedHat-7.yml index bd7083157fc..57b00da4095 100644 --- a/test/integration/targets/incidental_setup_docker/tasks/RedHat-7.yml +++ b/test/integration/targets/incidental_setup_docker/tasks/RedHat-7.yml @@ -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: diff --git a/test/integration/targets/setup_cron/tasks/main.yml b/test/integration/targets/setup_cron/tasks/main.yml index d7ce3303009..4a6b3bc00d2 100644 --- a/test/integration/targets/setup_cron/tasks/main.yml +++ b/test/integration/targets/setup_cron/tasks/main.yml @@ -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 diff --git a/test/integration/targets/setup_paramiko/uninstall-Fedora-35-python-3.yml b/test/integration/targets/setup_paramiko/uninstall-Fedora-35-python-3.yml index aa3387bae17..6d0e9a199dc 100644 --- a/test/integration/targets/setup_paramiko/uninstall-Fedora-35-python-3.yml +++ b/test/integration/targets/setup_paramiko/uninstall-Fedora-35-python-3.yml @@ -3,5 +3,3 @@ - name: Uninstall Paramiko and crypto policies scripts using dnf history undo command: dnf history undo last --assumeyes - args: - warn: no diff --git a/test/integration/targets/setup_paramiko/uninstall-dnf.yml b/test/integration/targets/setup_paramiko/uninstall-dnf.yml index ff0d39cede4..a56c0dd980a 100644 --- a/test/integration/targets/setup_paramiko/uninstall-dnf.yml +++ b/test/integration/targets/setup_paramiko/uninstall-dnf.yml @@ -1,4 +1,2 @@ - name: Uninstall Paramiko using dnf history undo command: dnf history undo last --assumeyes - args: - warn: no diff --git a/test/integration/targets/setup_paramiko/uninstall-yum.yml b/test/integration/targets/setup_paramiko/uninstall-yum.yml index f293d229938..de1c21f1b0f 100644 --- a/test/integration/targets/setup_paramiko/uninstall-yum.yml +++ b/test/integration/targets/setup_paramiko/uninstall-yum.yml @@ -1,4 +1,2 @@ - name: Uninstall Paramiko using yum history undo command: yum history undo last --assumeyes - args: - warn: no diff --git a/test/integration/targets/setup_paramiko/uninstall-zypper-python-2.yml b/test/integration/targets/setup_paramiko/uninstall-zypper-python-2.yml index 6bdb330778f..adb26e5c285 100644 --- a/test/integration/targets/setup_paramiko/uninstall-zypper-python-2.yml +++ b/test/integration/targets/setup_paramiko/uninstall-zypper-python-2.yml @@ -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 diff --git a/test/integration/targets/setup_paramiko/uninstall-zypper-python-3.yml b/test/integration/targets/setup_paramiko/uninstall-zypper-python-3.yml index cb0db9413ca..339be6fe2fc 100644 --- a/test/integration/targets/setup_paramiko/uninstall-zypper-python-3.yml +++ b/test/integration/targets/setup_paramiko/uninstall-zypper-python-3.yml @@ -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 diff --git a/test/integration/targets/yum_repository/tasks/main.yml b/test/integration/targets/yum_repository/tasks/main.yml index 90866523e04..7813af06ef2 100644 --- a/test/integration/targets/yum_repository/tasks/main.yml +++ b/test/integration/targets/yum_repository/tasks/main.yml @@ -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: diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index c8fd06ebd4d..1a40f9de79e 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -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