From a0c171ce1ba6ed3c94a92738e9b6b3976269e994 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 21 Dec 2017 11:35:32 -0500 Subject: [PATCH] fix command warnings, add action warnings (#34060) * fix command warnings, add action warnings --- lib/ansible/config/base.yml | 11 +++++++++++ lib/ansible/module_utils/basic.py | 6 +++++- lib/ansible/modules/commands/command.py | 5 ++++- lib/ansible/plugins/action/__init__.py | 4 +++- lib/ansible/plugins/callback/__init__.py | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index cb60781b98e..0baec404181 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -288,6 +288,17 @@ COLOR_WARN: env: [{name: ANSIBLE_COLOR_WARN}] ini: - {key: warn, section: colors} +ACTION_WARNINGS: + name: Toggle action warnings + default: True + description: + - By default Ansible will issue a warning when recieved from a task action (module or action plugin) + - These warnings can be silenced by adjusting this setting to False. + env: [{name: ANSIBLE_ACTION_WARNINGS}] + ini: + - {key: action_warnings, section: defaults} + type: boolean + version_added: "2.5" COMMAND_WARNINGS: name: Command module warnings default: True diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index a7eef260aab..82d1217b806 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -812,11 +812,12 @@ class AnsibleModule(object): self._warnings = [] self._deprecations = [] self._clean = {} + self._command_warn = True self.aliases = {} self._legal_inputs = ['_ansible_check_mode', '_ansible_no_log', '_ansible_debug', '_ansible_diff', '_ansible_verbosity', '_ansible_selinux_special_fs', '_ansible_module_name', '_ansible_version', '_ansible_syslog_facility', - '_ansible_socket', '_ansible_shell_executable'] + '_ansible_socket', '_ansible_shell_executable', '_ansible_command_warnings'] self._options_context = list() if add_file_common_args: @@ -1629,6 +1630,9 @@ class AnsibleModule(object): elif k == '_ansible_shell_executable' and v: self._shell = v + elif k == '_ansible_command_warnings' and v: + self._command_warn = v + elif check_invalid_arguments and k not in legal_inputs: unsupported_parameters.add(k) diff --git a/lib/ansible/modules/commands/command.py b/lib/ansible/modules/commands/command.py index 81bb333e1ee..73153dd2dda 100644 --- a/lib/ansible/modules/commands/command.py +++ b/lib/ansible/modules/commands/command.py @@ -165,7 +165,7 @@ def main(): executable=dict(), creates=dict(type='path'), removes=dict(type='path'), - warn=dict(type='bool', default=True), + warn=dict(type='bool'), stdin=dict(required=False), ) ) @@ -179,6 +179,9 @@ def main(): warn = module.params['warn'] stdin = module.params['stdin'] + if warn is None: + warn = module._command_warn + if not shell and executable: module.warn("As of Ansible 2.4, the parameter 'executable' is no longer supported with the 'command' module. Not using '%s'." % executable) executable = None diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 918ae167a6a..531b12e6b9e 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -36,7 +36,6 @@ from ansible.module_utils.json_utils import _filter_non_json_lines from ansible.module_utils.six import binary_type, string_types, text_type, iteritems, with_metaclass from ansible.module_utils.six.moves import shlex_quote from ansible.module_utils._text import to_bytes, to_native, to_text -from ansible.module_utils.connection import Connection from ansible.parsing.utils.jsonify import jsonify from ansible.release import __version__ from ansible.utils.unsafe_proxy import wrap_var @@ -613,6 +612,9 @@ class ActionBase(with_metaclass(ABCMeta, object)): # make sure all commands use the designated shell executable module_args['_ansible_shell_executable'] = self._play_context.executable + # let command know it should avoid specific warnings + module_args['_ansible_command_warnings'] = C.COMMAND_WARNINGS + def _update_connection_options(self, options, variables=None): ''' ensures connections have the appropriate information ''' update = {} diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 436e963e042..982f06ab839 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -125,7 +125,7 @@ class CallbackBase(AnsiblePlugin): def _handle_warnings(self, res): ''' display warnings, if enabled and any exist in the result ''' - if C.COMMAND_WARNINGS: + if C.ACTION_WARNINGS: if 'warnings' in res and res['warnings']: for warning in res['warnings']: self._display.warning(warning)