Merge "Connect using physical host's ansible_host var"

This commit is contained in:
Jenkins 2017-06-09 07:53:52 +00:00 committed by Gerrit Code Review
commit 1e7d489673
2 changed files with 6 additions and 2 deletions

View File

@ -58,8 +58,10 @@ class Connection(SSH.Connection):
self.physical_host = self._play_context.physical_host
else:
self.physical_host = None
def set_host_overrides(self, host, hostvars=None):
if self._container_check() or self._chroot_check():
self.host = self._play_context.remote_addr = self.physical_host
self.host = self._play_context.remote_addr = hostvars.get('physical_host_addr')
def exec_command(self, cmd, in_data=None, sudoable=True):
"""run a command on the remote host."""
@ -149,4 +151,3 @@ class Connection(SSH.Connection):
cmd = map(SSH.to_bytes, cmd)
p = SSH.subprocess.Popen(cmd, stdin=SSH.subprocess.PIPE, stdout=SSH.subprocess.PIPE, stderr=SSH.subprocess.PIPE)
p.communicate()

View File

@ -112,6 +112,9 @@ class StrategyModule(LINEAR.StrategyModule):
return
_play_context = copy.deepcopy(play_context)
if 'physical_host' in host.vars:
physical_host = self._inventory.get_host_variables(host.vars['physical_host'])
host.set_variable('physical_host_addr', physical_host['ansible_host'])
if task.delegate_to:
# If a task uses delegation change the play_context
# to use paramiko with pipelining disabled for this