fix command warnings, add action warnings (#34060)

* fix command warnings, add action warnings
This commit is contained in:
Brian Coca 2017-12-21 11:35:32 -05:00 committed by Toshio Kuratomi
parent 94d952f94b
commit a0c171ce1b
5 changed files with 24 additions and 4 deletions

View file

@ -288,6 +288,17 @@ COLOR_WARN:
env: [{name: ANSIBLE_COLOR_WARN}] env: [{name: ANSIBLE_COLOR_WARN}]
ini: ini:
- {key: warn, section: colors} - {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: COMMAND_WARNINGS:
name: Command module warnings name: Command module warnings
default: True default: True

View file

@ -812,11 +812,12 @@ class AnsibleModule(object):
self._warnings = [] self._warnings = []
self._deprecations = [] self._deprecations = []
self._clean = {} self._clean = {}
self._command_warn = True
self.aliases = {} self.aliases = {}
self._legal_inputs = ['_ansible_check_mode', '_ansible_no_log', '_ansible_debug', '_ansible_diff', '_ansible_verbosity', 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_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() self._options_context = list()
if add_file_common_args: if add_file_common_args:
@ -1629,6 +1630,9 @@ class AnsibleModule(object):
elif k == '_ansible_shell_executable' and v: elif k == '_ansible_shell_executable' and v:
self._shell = 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: elif check_invalid_arguments and k not in legal_inputs:
unsupported_parameters.add(k) unsupported_parameters.add(k)

View file

@ -165,7 +165,7 @@ def main():
executable=dict(), executable=dict(),
creates=dict(type='path'), creates=dict(type='path'),
removes=dict(type='path'), removes=dict(type='path'),
warn=dict(type='bool', default=True), warn=dict(type='bool'),
stdin=dict(required=False), stdin=dict(required=False),
) )
) )
@ -179,6 +179,9 @@ def main():
warn = module.params['warn'] warn = module.params['warn']
stdin = module.params['stdin'] stdin = module.params['stdin']
if warn is None:
warn = module._command_warn
if not shell and executable: 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) module.warn("As of Ansible 2.4, the parameter 'executable' is no longer supported with the 'command' module. Not using '%s'." % executable)
executable = None executable = None

View file

@ -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 import binary_type, string_types, text_type, iteritems, with_metaclass
from ansible.module_utils.six.moves import shlex_quote 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._text import to_bytes, to_native, to_text
from ansible.module_utils.connection import Connection
from ansible.parsing.utils.jsonify import jsonify from ansible.parsing.utils.jsonify import jsonify
from ansible.release import __version__ from ansible.release import __version__
from ansible.utils.unsafe_proxy import wrap_var 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 # make sure all commands use the designated shell executable
module_args['_ansible_shell_executable'] = self._play_context.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): def _update_connection_options(self, options, variables=None):
''' ensures connections have the appropriate information ''' ''' ensures connections have the appropriate information '''
update = {} update = {}

View file

@ -125,7 +125,7 @@ class CallbackBase(AnsiblePlugin):
def _handle_warnings(self, res): def _handle_warnings(self, res):
''' display warnings, if enabled and any exist in the result ''' ''' 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']: if 'warnings' in res and res['warnings']:
for warning in res['warnings']: for warning in res['warnings']:
self._display.warning(warning) self._display.warning(warning)