Skip to content

Commit

Permalink
Fix issue #23774 Make transport_test use exec
Browse files Browse the repository at this point in the history
Some ansible hosts are not directly reachable
via socket connections.  It is best to use
the transport mechanism itself than to assume
that the host is reachable via socket.

If we can exec a command, then the transport
is working.
  • Loading branch information
smikulcik committed Apr 20, 2017
1 parent c8e1679 commit 12d133c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
7 changes: 3 additions & 4 deletions lib/ansible/plugins/connection/accelerate.py
Expand Up @@ -101,10 +101,9 @@ def _connect(self):
def transport_test(self, connect_timeout):
''' Test the transport mechanism, if available '''
host = self._play_context.remote_addr
port = int(self._play_context.accelerate_port or 5099)
display.vvv("attempting transport test to %s:%s" % (host, port))
sock = socket.create_connection((host, port), connect_timeout)
sock.close()
display.vvv("attempting transport test to %s" % host)
self.reset()
self.exec_command("exit")

def send_data(self, data):
packed_len = struct.pack('!Q',len(data))
Expand Down
7 changes: 3 additions & 4 deletions lib/ansible/plugins/connection/paramiko_ssh.py
Expand Up @@ -135,10 +135,9 @@ class Connection(ConnectionBase):
def transport_test(self, connect_timeout):
''' Test the transport mechanism, if available '''
host = self._play_context.remote_addr
port = int(self._play_context.port or 22)
display.vvv("attempting transport test to %s:%s" % (host, port))
sock = socket.create_connection((host, port), connect_timeout)
sock.close()
display.vvv("attempting transport test to %s" % host)
self.reset()
self.exec_command("exit")

def _cache_key(self):
return "%s__%s__" % (self._play_context.remote_addr, self._play_context.remote_user)
Expand Down
7 changes: 3 additions & 4 deletions lib/ansible/plugins/connection/ssh.py
Expand Up @@ -214,10 +214,9 @@ def _connect(self):

def transport_test(self, connect_timeout):
''' Test the transport mechanism, if available '''
port = int(self.port or 22)
display.vvv("attempting transport test to %s:%s" % (self.host, port))
sock = socket.create_connection((self.host, port), connect_timeout)
sock.close()
display.vvv("attempting transport test to %s" % self.host)
self.reset()
self.exec_command("exit")

@staticmethod
def _create_control_path(host, port, user):
Expand Down
7 changes: 3 additions & 4 deletions lib/ansible/plugins/connection/winrm.py
Expand Up @@ -90,10 +90,9 @@ def __init__(self, *args, **kwargs):
def transport_test(self, connect_timeout):
''' Test the transport mechanism, if available '''
host = self._winrm_host
port = int(self._winrm_port)
display.vvv("attempting transport test to %s:%s" % (host, port))
sock = socket.create_connection((host, port), connect_timeout)
sock.close()
display.vvv("attempting transport test to %s" % host)
self.reset()
self.exec_command("Exit")

def set_host_overrides(self, host, hostvars=None):
'''
Expand Down

0 comments on commit 12d133c

Please sign in to comment.