From fd27afdc0d9b90a0b234cce1ad8d411615fb482f Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 9 May 2014 16:27:46 -0500 Subject: [PATCH] Adding ansible_shell_type and basic environment construction on it Previously we assumed the shell on the target systems were 'sh'- compliant when formatting environment variables preceding command strings. This patch corrects that by basing the target shell type on the DEFAULT_EXECUTABLE setting, which can be overridden on a per-host basis using the inventory variable 'ansible_shell_type'. Fixes #7352 --- docsite/rst/intro_inventory.rst | 2 ++ lib/ansible/runner/__init__.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docsite/rst/intro_inventory.rst b/docsite/rst/intro_inventory.rst index efa6653f52b..789f4ac438a 100644 --- a/docsite/rst/intro_inventory.rst +++ b/docsite/rst/intro_inventory.rst @@ -200,6 +200,8 @@ mentioned:: Connection type of the host. Candidates are local, ssh or paramiko. The default is paramiko before Ansible 1.2, and 'smart' afterwards which detects whether usage of 'ssh' would be feasible based on whether ControlPersist is supported. ansible_ssh_private_key_file Private key file used by ssh. Useful if using multiple keys and you don't want to use SSH agent. + ansible_shell_type + The shell type of the target system. By default commands are formatted using 'sh'-style syntax by default. Setting this to 'csh' or 'fish' will cause commands executed on target systems to follow those shell's syntax instead. ansible_python_interpreter The target host python path. This is useful for systems with more than one Python or not located at "/usr/bin/python" such as \*BSD, or where /usr/bin/python diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 7b943003f2e..cd09993e587 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -287,6 +287,10 @@ class Runner(object): def _compute_environment_string(self, inject=None): ''' what environment variables to use when running the command? ''' + shell_type = inject.get('ansible_shell_type') + if not shell_type: + shell_type = os.path.basename(C.DEFAULT_EXECUTABLE) + default_environment = dict( LANG = C.DEFAULT_MODULE_LANG, LC_CTYPE = C.DEFAULT_MODULE_LANG, @@ -301,7 +305,10 @@ class Runner(object): result = "" for (k,v) in default_environment.iteritems(): - result = "%s=%s %s" % (k, pipes.quote(unicode(v)), result) + if shell_type in ('csh', 'fish'): + result = "env %s=%s %s" % (k, pipes.quote(unicode(v)), result) + else: + result = "%s=%s %s" % (k, pipes.quote(unicode(v)), result) return result # *****************************************************