diff options
author | Peter Sprygada <privateip@users.noreply.github.com> | 2017-02-18 08:12:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-18 08:12:01 -0500 |
commit | e05b2b56f201546f791ec4cdd52d086bb786c09d (patch) | |
tree | 39e173403f58f481acc3a2f891845a4e81adf98e /bin | |
parent | 6a0fb4e3b69dbe776757691915515b33ee011633 (diff) | |
download | ansible-e05b2b56f201546f791ec4cdd52d086bb786c09d.tar.gz |
capture AnsibleConnectionFailure messages in ansible-connection (#21612)
Send the messages to the log file
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/ansible-connection | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/bin/ansible-connection b/bin/ansible-connection index 845a053b95..c0b159dfc3 100755 --- a/bin/ansible-connection +++ b/bin/ansible-connection @@ -117,7 +117,7 @@ class Server(): 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._connect() @@ -222,7 +222,7 @@ class Server(): # the socket file so it can be recreated end_time = datetime.datetime.now() 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: self.conn.close() self.socket.close() @@ -254,6 +254,8 @@ def main(): sys.stderr.write(traceback.format_exc()) sys.exit("FAIL: %s" % e) + display.verbosity = pc.verbosity + ssh = connection_loader.get('ssh', class_only=True) 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): pid = do_fork() if pid == 0: + rc = 0 try: server = Server(sf_path, pc) + except AnsibleConnectionFailure as exc: + display.vvv(str(exc), pc.remote_addr) + rc = 1 except Exception as exc: display.vvv(traceback.format_exc(), pc.remote_addr) + rc = 1 fcntl.lockf(lock_fd, fcntl.LOCK_UN) os.close(lock_fd) - server.run() - sys.exit(0) + if rc == 0: + server.run() + sys.exit(rc) fcntl.lockf(lock_fd, fcntl.LOCK_UN) os.close(lock_fd) @@ -302,7 +310,7 @@ def main(): time.sleep(C.PERSISTENT_CONNECT_INTERVAL) attempts += 1 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) # send the play_context back into the connection so the connection |