From 5b1d8cfd5c401ee29f09bcf7924e5e6f7b46f8f7 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Tue, 2 Feb 2016 11:46:09 -0800 Subject: [PATCH] Establish sh as the default shell plugin. This is a fix for one of the problems pointed out in #14176 --- lib/ansible/plugins/connection/__init__.py | 7 ++++++- lib/ansible/plugins/shell/csh.py | 5 +++++ lib/ansible/plugins/shell/fish.py | 5 +++++ lib/ansible/plugins/shell/powershell.py | 7 +++++++ lib/ansible/plugins/shell/sh.py | 7 +++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index bea8e5b426b..2dfb2229107 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -83,7 +83,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 bd210f12feb..6f1008be012 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 342de99e5f8..aee4cf0867b 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 096a0cf95d6..acde565e2fc 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 8b20338a603..6fbb7439cc5 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'