Connect using physical host's ansible_host var

Within the strategy plugin set a host var, 'physical_host_addr', which
corresponds to the 'ansible_host' var of the host's 'physical_host'.

Use this within the connection plugin rather than the hostname of the
physical host, which may not exist in DNS or the deployment host's
hosts file.

Closes-Bug: 1695944
Change-Id: I75f9d0f55ecd875caa1bf608a77c92f950b679a1
This commit is contained in:
Jimmy McCrory 2017-06-07 21:36:06 -07:00
parent d1ca01f082
commit 8f8d9cfa11
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