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
This commit is contained in:
James Cammarata 2014-05-09 16:27:46 -05:00
commit fd27afdc0d
2 changed files with 10 additions and 1 deletions

View file

@ -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
# *****************************************************