Make ansible_python_interpreter work with synchronize

Fixes #11836
pull/8127/merge
Toshio Kuratomi 9 years ago
parent 8279557e8f
commit f0431eaea9

@ -46,6 +46,7 @@ class Inventory(object):
# 'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache', '_groups_list',
# '_pattern_cache', '_vault_password', '_vars_plugins', '_playbook_basedir']
LOCALHOST_ALIASES = frozenset(('localhost', '127.0.0.1', '::1'))
def __init__(self, loader, variable_manager, host_list=C.DEFAULT_HOST_LIST):
# the host file file, or script path, or list of hosts
@ -368,7 +369,7 @@ class Inventory(object):
for host in matching_hosts:
__append_host_to_results(host)
if pattern in ["localhost", "127.0.0.1", "::1"] and len(results) == 0:
if pattern in self.LOCALHOST_ALIASES and len(results) == 0:
new_host = self._create_implicit_localhost(pattern)
results.append(new_host)
return results
@ -401,12 +402,15 @@ class Inventory(object):
def get_host(self, hostname):
if hostname not in self._hosts_cache:
self._hosts_cache[hostname] = self._get_host(hostname)
if hostname in self.LOCALHOST_ALIASES:
for host in self.LOCALHOST_ALIASES.difference((hostname,)):
self._hosts_cache[host] = self._hosts_cache[hostname]
return self._hosts_cache[hostname]
def _get_host(self, hostname):
if hostname in ['localhost', '127.0.0.1', '::1']:
if hostname in self.LOCALHOST_ALIASES:
for host in self.get_group('all').get_hosts():
if host.name in ['localhost', '127.0.0.1', '::1']:
if host.name in self.LOCALHOST_ALIASES:
return host
return self._create_implicit_localhost(hostname)
else:
@ -502,7 +506,7 @@ class Inventory(object):
""" return a list of hostnames for a pattern """
result = [ h for h in self.get_hosts(pattern) ]
if len(result) == 0 and pattern in ["localhost", "127.0.0.1", "::1"]:
if len(result) == 0 and pattern in self.LOCALHOST_ALIASES:
result = [pattern]
return result

@ -70,6 +70,27 @@ class ActionModule(ActionBase):
return return_data
def _override_module_replaced_vars(self, task_vars):
""" Some vars are substituted into the modules. Have to make sure
that those are correct for localhost when synchronize creates its own
connection to localhost."""
# Clear the current definition of these variables as they came from the
# connection to the remote host
if 'ansible_syslog_facility' in task_vars:
del task_vars['ansible_syslog_facility']
for key in task_vars:
if key.startswith("ansible_") and key.endswith("_interpreter"):
del task_vars[key]
# Add the definition from localhost
localhost = task_vars['hostvars']['localhost']
if 'ansible_syslog_facility' in localhost:
task_vars['ansible_syslog_facility'] = localhost['ansible_syslog_facility']
for key in localhost:
if key.startswith("ansible_") and key.endswith("_interpreter"):
task_vars[key] = localhost[key]
def run(self, tmp=None, task_vars=dict()):
''' generates params and passes them on to the rsync module '''
@ -132,6 +153,7 @@ class ActionModule(ActionBase):
new_connection = connection_loader.get('local', self._play_context, new_stdin)
self._connection = new_connection
transport_overridden = True
self._override_module_replaced_vars(task_vars)
### FIXME: We think that this was here for v1 because the local
# connection didn't support sudo. In v2 it does so we think it's
# safe to remove this now.

Loading…
Cancel
Save