capture AnsibleConnectionFailure messages in ansible-connection (#21612)

Send the messages to the log file
pull/21616/head
Peter Sprygada 8 years ago committed by GitHub
parent 6a0fb4e3b6
commit e05b2b56f2

@ -117,7 +117,7 @@ class Server():
self._start_time = datetime.datetime.now() self._start_time = datetime.datetime.now()
display.vvv("setup connection %s" % self.play_context.connection, play_context.remote_addr) display.vvv("using connection %s" % self.play_context.connection, play_context.remote_addr)
self.conn = connection_loader.get(play_context.connection, play_context, sys.stdin) self.conn = connection_loader.get(play_context.connection, play_context, sys.stdin)
self.conn._connect() self.conn._connect()
@ -222,7 +222,7 @@ class Server():
# the socket file so it can be recreated # the socket file so it can be recreated
end_time = datetime.datetime.now() end_time = datetime.datetime.now()
delta = end_time - self._start_time delta = end_time - self._start_time
display.v('shutting down connection, connection was active for %s secs' % delta, self.play_context.remote_addr) display.v('shutting down control socket, connection was active for %s secs' % delta, self.play_context.remote_addr)
try: try:
self.conn.close() self.conn.close()
self.socket.close() self.socket.close()
@ -254,6 +254,8 @@ def main():
sys.stderr.write(traceback.format_exc()) sys.stderr.write(traceback.format_exc())
sys.exit("FAIL: %s" % e) sys.exit("FAIL: %s" % e)
display.verbosity = pc.verbosity
ssh = connection_loader.get('ssh', class_only=True) ssh = connection_loader.get('ssh', class_only=True)
m = ssh._create_control_path(pc.remote_addr, pc.port, pc.remote_user) m = ssh._create_control_path(pc.remote_addr, pc.port, pc.remote_user)
@ -270,14 +272,20 @@ def main():
if not os.path.exists(sf_path): if not os.path.exists(sf_path):
pid = do_fork() pid = do_fork()
if pid == 0: if pid == 0:
rc = 0
try: try:
server = Server(sf_path, pc) server = Server(sf_path, pc)
except AnsibleConnectionFailure as exc:
display.vvv(str(exc), pc.remote_addr)
rc = 1
except Exception as exc: except Exception as exc:
display.vvv(traceback.format_exc(), pc.remote_addr) display.vvv(traceback.format_exc(), pc.remote_addr)
rc = 1
fcntl.lockf(lock_fd, fcntl.LOCK_UN) fcntl.lockf(lock_fd, fcntl.LOCK_UN)
os.close(lock_fd) os.close(lock_fd)
server.run() if rc == 0:
sys.exit(0) server.run()
sys.exit(rc)
fcntl.lockf(lock_fd, fcntl.LOCK_UN) fcntl.lockf(lock_fd, fcntl.LOCK_UN)
os.close(lock_fd) os.close(lock_fd)
@ -302,7 +310,7 @@ def main():
time.sleep(C.PERSISTENT_CONNECT_INTERVAL) time.sleep(C.PERSISTENT_CONNECT_INTERVAL)
attempts += 1 attempts += 1
if attempts > C.PERSISTENT_CONNECT_RETRIES: if attempts > C.PERSISTENT_CONNECT_RETRIES:
sys.stderr.write('failed to connect to the listener socket, connection timeout.') sys.stderr.write('failed to connect to control socket')
sys.exit(255) sys.exit(255)
# send the play_context back into the connection so the connection # send the play_context back into the connection so the connection

Loading…
Cancel
Save