Agent Wranglers

INF-45Recommended

Rebuild any server from code

Keep everything needed to rebuild each server in code, so one command builds a fresh one. Prove it on a new machine in the quarterly restore drill.

How to do it

The single server is the place where hand-made setup piles up. Write down every package, setting, user, timer and firewall rule in code. Keep the data apart and restore it as in the restore runbook. Time the drill from an empty machine to a passing health check, against the service's recovery time objective.

Examples

Shell example

# Drill: a fresh machine, the same code, then the health check
tofu apply -var="name=shop-drill"
ansible-playbook -i shop-drill.example.com, site.yml
./restore-latest-backup.sh shop-drill.example.com
curl -fsS https://shop-drill.example.com/health

How to check

The last rebuild drill is under 3 months old. It built a working server from code and backups within the recovery time objective, without logging in to fix anything.

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/servers/rebuild-from-scratch">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.