Playbook works on the first run, later runs fail with `Connection reset by peer` right after a handler restarts `sshd`
IntermediateTroubleshootingConnection and SSH Failures
Answer
Likely causes → restarted kills the connection Ansible is using; or a config error prevents sshd from coming back.
Diagnose → Check systemctl status sshd from the console; verify with sshd -t.
Fix → Use state: reloaded, validate before installing the config, and add meta: reset_connection after the change.
- ansible.builtin.meta: reset_connection
Prevent → validate: sshd -t -f %s on every sshd config task.
More on Connection and SSH Failures
`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password)."}`Beginner`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host 10.0.1.15 port 22: Connection timed out"}`Beginner`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host web01 port 22: Connection refused"}`Beginner`Host key verification failed.` after rebuilding a serverBeginnerThe playbook hangs for ever at "Gathering Facts" on one hostIntermediate`Failed to connect to the host via ssh: Too many authentication failures`Intermediate