From 41414ed47548ac0edcd4c7c83c0c3bd7b6011546 Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Tue, 7 Jul 2020 18:40:38 -0500 Subject: [PATCH] Deprecate command warnings feature (#70504) Change: - The command warnings feature which suggests that users use modules instead of certain commands is now deprecated. Its `warn` paramater and `COMMAND_WARNINGS` configuration options are also deprecated. Their use will become an error in version 2.13. Test Plan: - CI Signed-off-by: Rick Elrod Co-authored-by: Sam Doran --- .../command-warnings-deprecation.yml | 2 + lib/ansible/config/base.yml | 9 +++- lib/ansible/modules/command.py | 8 +-- .../targets/command_shell/tasks/main.yml | 53 ------------------- 4 files changed, 14 insertions(+), 58 deletions(-) create mode 100644 changelogs/fragments/command-warnings-deprecation.yml diff --git a/changelogs/fragments/command-warnings-deprecation.yml b/changelogs/fragments/command-warnings-deprecation.yml new file mode 100644 index 00000000000..cd1d200147f --- /dev/null +++ b/changelogs/fragments/command-warnings-deprecation.yml @@ -0,0 +1,2 @@ +deprecated_features: + - Starting in 2.14, shell and command modules will no longer have the option to warn and suggest modules in lieu of commands. The ``warn`` parameter to these modules is now deprecated and defaults to ``False``. Similarly, the ``COMMAND_WARNINGS`` configuration option is also deprecated and defaults to ``False``. These will be removed and their presence will become an error in 2.14. diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index c3da6178ce8..0dbb8929596 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -416,15 +416,20 @@ ACTION_WARNINGS: version_added: "2.5" COMMAND_WARNINGS: name: Command module warnings - default: True + default: False description: - - By default Ansible will issue a warning when the shell or command module is used and the command appears to be similar to an existing Ansible module. + - 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" + alternatives: N/A, these are just warnings and we no longer plan to show them. 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 5844c2d8493..e6533d2fa56 100644 --- a/lib/ansible/modules/command.py +++ b/lib/ansible/modules/command.py @@ -58,9 +58,11 @@ options: version_added: "0.6" warn: description: - - Enable or disable task warnings. + - (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: yes + default: no version_added: "1.8" stdin: description: @@ -259,7 +261,7 @@ 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=True), + 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), diff --git a/test/integration/targets/command_shell/tasks/main.yml b/test/integration/targets/command_shell/tasks/main.yml index 1d614e49456..1b2644bff18 100644 --- a/test/integration/targets/command_shell/tasks/main.yml +++ b/test/integration/targets/command_shell/tasks/main.yml @@ -3,46 +3,6 @@ # Copyright: (c) 2014, Richard Isaacson # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -- name: use command to execute sudo - command: sudo -h - register: become - -- name: assert become warning was reported - assert: - that: - - "become.warnings | length() == 1" - - "'Consider using' in become.warnings[0]" - -- name: use command to execute sudo without warnings - command: sudo -h warn=no - register: become - -- name: assert become warning was not reported - assert: - that: - - "'warnings' not in become" - -- name: use command to execute tar - command: tar --help - register: tar - -- name: assert tar warning was reported - assert: - that: - - tar.warnings | length() == 1 - - '"Consider using the unarchive module rather than running ''tar''" in tar.warnings[0]' - -- name: use command to execute chown - command: chown -h - register: chown - ignore_errors: true - -- name: assert chown warning was reported - assert: - that: - - chown.warnings | length() == 1 - - '"Consider using the file module with owner rather than running ''chown''" in chown.warnings[0]' - - name: use command with unsupported executable arg command: ls /dev/null args: @@ -56,19 +16,6 @@ - executable.warnings | length() == 1 - "'no longer supported' in executable.warnings[0]" -# The warning isn't on the task since it comes from the action plugin. Not sure -# how to test for that. -# -# - name: Use command with reboot -# command: sleep 2 && /not/shutdown -r now -# ignore_errors: yes -# register: reboot - -# - name: Assert that reboot warning was issued -# assert: -# that: -# - '"Consider using the reboot module" in reboot.warnings[0]' - - name: use command with no command command: args: