wait_for_connection: Wait for system to become reachable (#20011)

* WIP: wait_for_connection: Wait for system to be reachable

This action plugin allows to check when a system is back online and
usable by Ansible.

As an example, when doing a SysPrep and running Enable-WinRM.ps1, it
takes between 10 to 20 seconds between the WinRM TCP port to open, and
it actually being able to server Ansible requests. This time is variable
and depends on the boot process.

Current implementation is specific for Windows (WinRM) only, this will
be fixed shortly.

This fixes #19998

* Support other transport types

* Various improvements

- Fix reported typo
- Add transport_test support in accelerate plugin
- Ensure port is an integer

* Improve examples

* Small fixes

- Use correct ConfigureRemotingForAnsible.ps1 script name
- Only use win_ping when remote shell is known to be Powershell
- Add integration tests to CI framework
This commit is contained in:
Dag Wieers 2017-03-01 20:00:49 +01:00 committed by Matt Davis
parent 0bd2714122
commit 52959ebdc1
9 changed files with 270 additions and 1 deletions

View file

@ -25,6 +25,7 @@ import fcntl
import hashlib
import os
import pty
import socket
import subprocess
import time
@ -61,7 +62,7 @@ class Connection(ConnectionBase):
super(Connection, self).__init__(*args, **kwargs)
self.host = self._play_context.remote_addr
self.port = self._play_context.port
self.port = int(self._play_context.port or 22)
self.user = self._play_context.remote_user
self.control_path = C.ANSIBLE_SSH_CONTROL_PATH
self.control_path_dir = C.ANSIBLE_SSH_CONTROL_PATH_DIR
@ -73,6 +74,12 @@ class Connection(ConnectionBase):
def _connect(self):
return self
def transport_test(self, connect_timeout):
''' Test the transport mechanism, if available '''
display.vvv("attempting transport test to %s:%s" % (self.host, self.port))
sock = socket.create_connection((self.host, self.port), connect_timeout)
sock.close()
@staticmethod
def _create_control_path(host, port, user):
'''Make a hash for the controlpath based on con attributes'''