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
pull/7253/head
James Cammarata 11 years ago
parent 62c4a15c73
commit fd27afdc0d

@ -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. 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 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. 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 ansible_python_interpreter
The target host python path. This is useful for systems with more 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 than one Python or not located at "/usr/bin/python" such as \*BSD, or where /usr/bin/python

@ -287,6 +287,10 @@ class Runner(object):
def _compute_environment_string(self, inject=None): def _compute_environment_string(self, inject=None):
''' what environment variables to use when running the command? ''' ''' 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( default_environment = dict(
LANG = C.DEFAULT_MODULE_LANG, LANG = C.DEFAULT_MODULE_LANG,
LC_CTYPE = C.DEFAULT_MODULE_LANG, LC_CTYPE = C.DEFAULT_MODULE_LANG,
@ -301,7 +305,10 @@ class Runner(object):
result = "" result = ""
for (k,v) in default_environment.iteritems(): 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 return result
# ***************************************************** # *****************************************************

Loading…
Cancel
Save