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.

Votre progression est enregistrée dans ce navigateur uniquement.

Envoyer pour relecture (10 points)