Interview Prep/Ansible/Connection and SSH Failures

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.

All Ansible questions Roadmap: Ansible

More on Connection and SSH Failures