Remove shell module specialcases

Shell is implemented via the command module.  There was a special case
in mod_args to do that.  Make shell into an action plugin to handle that
instead.

Also move the special case for the command nanny into a command module
action plugin.  This is more appropriate as we then do not have to send
a parameter that is only for the command module to every single module.
This commit is contained in:
Toshio Kuratomi
2017-12-21 10:45:33 -08:00
parent 39800e1390
commit 235bdfb996
8 changed files with 125 additions and 103 deletions

View File

@@ -812,12 +812,11 @@ 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_command_warnings']
'_ansible_socket', '_ansible_shell_executable']
self._options_context = list()
if add_file_common_args:
@@ -1630,9 +1629,6 @@ 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)

View File

@@ -165,7 +165,8 @@ def main():
executable=dict(),
creates=dict(type='path'),
removes=dict(type='path'),
warn=dict(type='bool'),
# The default for this really comes from the action plugin
warn=dict(type='bool', default=True),
stdin=dict(required=False),
)
)
@@ -179,9 +180,6 @@ 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

View File

@@ -116,21 +116,6 @@ class ModuleArgsParser:
else:
return (tokens[0], "")
def _handle_shell_weirdness(self, action, args):
'''
given an action name and an args dictionary, return the
proper action name and args dictionary. This mostly is due
to shell/command being treated special and nothing else
'''
# the shell module really is the command module with an additional
# parameter
if action == 'shell':
action = 'command'
args['_uses_shell'] = True
return (action, args)
def _normalize_parameters(self, thing, action=None, additional_args=None):
'''
arguments can be fuzzy. Deal with all the forms.
@@ -319,7 +304,4 @@ class ModuleArgsParser:
", ".join(RAW_PARAM_MODULES)),
obj=self._task_ds)
# shell modules require special handling
(action, args) = self._handle_shell_weirdness(action, args)
return (action, args, delegate_to)

View File

@@ -612,9 +612,6 @@ 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 = {}

View File

@@ -0,0 +1,25 @@
# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible import constants as C
from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash
class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
self._supports_async = True
results = super(ActionModule, self).run(tmp, task_vars)
# Command module has a special config option to turn off the command nanny warnings
if 'warn' not in self._task.args:
self._task.args['warn'] = C.COMMAND_WARNINGS
wrap_async = self._task.async_val and not self._connection.has_native_async
results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars, wrap_async=wrap_async))
return results

View File

@@ -0,0 +1,25 @@
# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash
class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
# Shell module is implemented via command
self._task.action = 'command'
self._task.args['_uses_shell'] = True
command_action = self._shared_loader_obj.action_loader.get('command',
task=self._task,
connection=self._connection,
play_context=self._play_context,
loader=self._loader,
templar=self._templar,
shared_loader_obj=self._shared_loader_obj)
return command_action.run(task_vars=task_vars)