Audit first, change later: server-hardening
I made a project that hardens Ubuntu and Debian servers with Ansible, and by default only audits and changes nothing.
Most hardening playbooks start by changing things. server-hardening looks first. By default it only reads the server and writes a report to my computer: which ports are listening, how SSH is configured, which updates are pending. Every fix is its own category and they all ship turned off. I do a dry run first and enable them one by one. The Lynis score can also be compared before and after.
I wrote it for a real server that runs a live website. On a server like that, a careless playbook can lock the owner out.
Not locking yourself out
The SSH setting is validated before it is put in place, and if anything fails the old file is restored. If the session has no valid key, it refuses to turn off password login. At the end it opens a new connection to check that login still works. Running a playbook twice should change nothing the second time, and CI checks that too.
What it does not do
Original files are backed up before every change and can be restored with the rollback playbook. There are also things it deliberately does not do: it does not change the SSH port, does not reboot the server, and does not remove packages.