diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index f101c07d9f..ccca0b3d4b 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -84,7 +84,12 @@ class ConnectionBase(with_metaclass(ABCMeta, object)): elif hasattr(self, '_shell_type'): shell_type = getattr(self, '_shell_type') else: - shell_type = os.path.basename(C.DEFAULT_EXECUTABLE) + shell_type = 'sh' + shell_filename = os.path.basename(C.DEFAULT_EXECUTABLE) + for shell in shell_loader.all(): + if shell_filename in shell.COMPATIBLE_SHELLS: + shell_type = shell.SHELL_FAMILY + break self._shell = shell_loader.get(shell_type) if not self._shell: diff --git a/lib/ansible/plugins/shell/csh.py b/lib/ansible/plugins/shell/csh.py index bd210f12fe..6f1008be01 100644 --- a/lib/ansible/plugins/shell/csh.py +++ b/lib/ansible/plugins/shell/csh.py @@ -21,6 +21,11 @@ from ansible.plugins.shell.sh import ShellModule as ShModule class ShellModule(ShModule): + # Common shell filenames that this plugin handles + COMPATIBLE_SHELLS = frozenset(('csh', 'tcsh')) + # Family of shells this has. Must match the filename without extension + SHELL_FAMILY = 'csh' + # How to end lines in a python script one-liner _SHELL_EMBEDDED_PY_EOL = '\\\n' _SHELL_REDIRECT_ALLNULL = '>& /dev/null' diff --git a/lib/ansible/plugins/shell/fish.py b/lib/ansible/plugins/shell/fish.py index 342de99e5f..aee4cf0867 100644 --- a/lib/ansible/plugins/shell/fish.py +++ b/lib/ansible/plugins/shell/fish.py @@ -21,6 +21,11 @@ from ansible.plugins.shell.sh import ShellModule as ShModule class ShellModule(ShModule): + # Common shell filenames that this plugin handles + COMPATIBLE_SHELLS = frozenset(('fish',)) + # Family of shells this has. Must match the filename without extension + SHELL_FAMILY = 'fish' + _SHELL_AND = '; and' _SHELL_OR = '; or' _SHELL_SUB_LEFT = '(' diff --git a/lib/ansible/plugins/shell/powershell.py b/lib/ansible/plugins/shell/powershell.py index 096a0cf95d..acde565e2f 100644 --- a/lib/ansible/plugins/shell/powershell.py +++ b/lib/ansible/plugins/shell/powershell.py @@ -36,6 +36,13 @@ if _powershell_version: class ShellModule(object): + # Common shell filenames that this plugin handles + # Powershell is handled differently. It's selected when winrm is the + # connection + COMPATIBLE_SHELLS = frozenset() + # Family of shells this has. Must match the filename without extension + SHELL_FAMILY = 'powershell' + def env_prefix(self, **kwargs): return '' diff --git a/lib/ansible/plugins/shell/sh.py b/lib/ansible/plugins/shell/sh.py index 8b20338a60..6fbb7439cc 100644 --- a/lib/ansible/plugins/shell/sh.py +++ b/lib/ansible/plugins/shell/sh.py @@ -30,6 +30,13 @@ _USER_HOME_PATH_RE = re.compile(r'^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$') class ShellModule(object): + # Common shell filenames that this plugin handles. + # Note: sh is the default shell plugin so this plugin may also be selected + # if the filename is not listed in any Shell plugin. + COMPATIBLE_SHELLS = frozenset(('sh', 'zsh', 'bash', 'dash', 'ksh')) + # Family of shells this has. Must match the filename without extension + SHELL_FAMILY = 'sh' + # How to end lines in a python script one-liner _SHELL_EMBEDDED_PY_EOL = '\n' _SHELL_REDIRECT_ALLNULL = '> /dev/null 2>&1'