Automation & Scripting

Capstone: An Automated Operations Toolkit

45 min

Bring the whole track together in one repository, ops-toolkit, that you could hand to a client or a new teammate.

Requirements

  1. Backups โ€” a Python script that dumps the database, compresses and encrypts it, uploads it off-site and prunes old copies. It supports --dry-run, logs every step and exits non-zero on failure.
  2. Health checks โ€” a script that checks disk, memory, a list of URLs and certificate expiry dates (ssl.get_server_certificate or openssl s_client), and posts a summary to Slack or Discord only when something needs attention.
  3. Scheduling โ€” systemd timers (or cron with flock) for both, with heartbeat pings.
  4. Server setup โ€” an Ansible playbook that installs the toolkit, its timers and its config on any server.
  5. CI โ€” GitHub Actions running ShellCheck, pyflakes and pytest on every push.
  6. Docs โ€” a README covering install, configuration (every env var), how to restore a backup and how to add a new check.

Suggested layout

ops-toolkit/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ backup.py
โ”‚   โ””โ”€โ”€ healthcheck.py
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_backup.py
โ”‚   โ””โ”€โ”€ test_healthcheck.py
โ”œโ”€โ”€ systemd/
โ”‚   โ”œโ”€โ”€ ops-backup.service
โ”‚   โ””โ”€โ”€ ops-backup.timer
โ”œโ”€โ”€ ansible/
โ”‚   โ”œโ”€โ”€ inventory.example.ini
โ”‚   โ””โ”€โ”€ site.yml
โ””โ”€โ”€ .github/workflows/ci.yml

Testing automation code

Automation fails in production when it was never tested. Make functions small and pure where possible, then test them:

from scripts.healthcheck import over_threshold

def test_over_threshold():
    assert over_threshold(used=85, total=100, limit=80)
    assert not over_threshold(used=50, total=100, limit=80)

For steps that touch the outside world, test the --dry-run path and mock network calls.

Review checklist

  • [ ] Every script is idempotent and safe to re-run
  • [ ] No secrets in the repository; .env.example documents them all
  • [ ] Failures alert a human; silence is detected with heartbeats
  • [ ] Restores have been tested, with the time it took written down
  • [ ] A new teammate can install it from the README alone

Finish this and you have a real portfolio piece. It is also exactly the kind of maintenance package businesses pay for every month.

Your progress is saved in this browser only.

Submit for review (10 points)