From 8f8d9cfa11d6e1ca9426d53f99b6aa20bd331579 Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Wed, 7 Jun 2017 21:36:06 -0700 Subject: [PATCH] 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 --- connection/ssh.py | 5 +++-- strategy/linear.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/connection/ssh.py b/connection/ssh.py index 2e4e1ff..1931e60 100644 --- a/connection/ssh.py +++ b/connection/ssh.py @@ -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() - diff --git a/strategy/linear.py b/strategy/linear.py index dbece34..dd3486a 100644 --- a/strategy/linear.py +++ b/strategy/linear.py @@ -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