Skip to content

Commit eed2407

Browse files
authored
adds connection established message to ansible-connection (#22492)
This will now print a log message that displays how long the ssh connection took to establish to the remote device. If the connection established time is exceed it will also print a message to the log file that the connection attempts have exceed. Updates default connection retries to 30 fixes #22319
1 parent 771b14a commit eed2407

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

bin/ansible-connection

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class Server():
126126
if not self.conn.connected:
127127
raise AnsibleConnectionFailure('unable to connect to remote host')
128128

129+
connection_time = datetime.datetime.now() - self._start_time
130+
display.vvvv('connection established in %s' % connection_time, play_context.remote_addr)
131+
129132
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
130133
self.socket.bind(path)
131134
self.socket.listen(1)
@@ -321,6 +324,8 @@ def main():
321324
time.sleep(C.PERSISTENT_CONNECT_INTERVAL)
322325
attempts += 1
323326
if attempts > C.PERSISTENT_CONNECT_RETRIES:
327+
display.vvvv('number of connection attempts exceeded, unable to connect to control socket')
328+
display.vvvv('persistent_connect_interval=%s, persistent_connect_retries=%s' % (C.PERSISTENT_CONNECT_INTERVAL, C.PERSISTENT_CONNECT_RETRIES))
324329
sys.stderr.write('failed to connect to control socket')
325330
sys.exit(255)
326331

lib/ansible/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def load_config_file():
347347
PARAMIKO_PROXY_COMMAND = get_config(p, 'paramiko_connection', 'proxy_command', 'ANSIBLE_PARAMIKO_PROXY_COMMAND', None)
348348
PARAMIKO_LOOK_FOR_KEYS = get_config(p, 'paramiko_connection', 'look_for_keys', 'ANSIBLE_PARAMIKO_LOOK_FOR_KEYS', True, value_type='boolean')
349349
PERSISTENT_CONNECT_TIMEOUT = get_config(p, 'persistent_connection', 'connect_timeout', 'ANSIBLE_PERSISTENT_CONNECT_TIMEOUT', 30, value_type='integer')
350-
PERSISTENT_CONNECT_RETRIES = get_config(p, 'persistent_connection', 'connect_retries', 'ANSIBLE_PERSISTENT_CONNECT_RETRIES', 10, value_type='integer')
350+
PERSISTENT_CONNECT_RETRIES = get_config(p, 'persistent_connection', 'connect_retries', 'ANSIBLE_PERSISTENT_CONNECT_RETRIES', 30, value_type='integer')
351351
PERSISTENT_CONNECT_INTERVAL = get_config(p, 'persistent_connection', 'connect_interval', 'ANSIBLE_PERSISTENT_CONNECT_INTERVAL', 1, value_type='integer')
352352

353353
# obsolete -- will be formally removed

0 commit comments

Comments
 (0)