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: