def wait_for_connection(addr, port, inventory, group, end):
env = os.environ.copy()
env.update(dict(ANSIBLE_HOST_KEY_CHECKING='False'))
while(True):
if time.time() > end:
message = 'Timeout while connecting to {}:{}'.format(addr, port)
raise ConnectionTimeout(message)
try:
# First check if port is open.
socket.create_connection((addr, port), 1)
# We didn't raise an exception, so port is open.
# Now check if we can actually log in.
with open('/dev/null', 'wb') as devnull:
ret = subprocess.call([
'ansible', group,
'-i', inventory, '-m', 'raw', '-a', 'exit'
], stderr=devnull, stdout=devnull, env=env)
if ret == 0:
break
else:
raise
except:
time.sleep(15)
评论列表
文章目录