Skip to content

Instantly share code, notes, and snippets.

@df-a
Last active March 10, 2023 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save df-a/80a21d8162fefbbca130bb50701d85f5 to your computer and use it in GitHub Desktop.
Save df-a/80a21d8162fefbbca130bb50701d85f5 to your computer and use it in GitHub Desktop.
Keep Ansible connection alive

The SSH keepalive value determines how often an idle SSH connection will send a message to the remote host to keep the connection alive. If the connection is idle for longer than the keepalive value, the connection will be closed.

To prevent Ansible from hanging due to idle SSH connections, it is recommended to set an appropriate SSH keepalive value. A common value for this parameter is 60 seconds. This value can be set in the ssh_args parameter in your Ansible inventory file, like this:

ansible_ssh_common_args='-o ServerAliveInterval=60'

Alternatively, you can set this value in your SSH configuration file (~/.ssh/config) using the following syntax:

Host *
  ServerAliveInterval 60

This will ensure that Ansible sends a keepalive message every 60 seconds to keep the SSH connection alive and prevent it from timing out. You can adjust this value based on your specific requirements and the behavior of your target hosts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment