Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

You need to push a config file to 20 servers and restart a service, but only if the file changed. How in Python?

IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Idempotent config push; Ansible's template + handler does this.

What I'd do →

  1. Compute local SHA-256; on each host run sha256sum on the remote file via Fabric.
  2. If different: c.put() to a temp path, validate (nginx -t -c ...), sudo mv into place, sudo systemctl reload.
  3. Roll through hosts in batches and stop on the first failure.
  4. Suggest Ansible for anything beyond this.

Why → Comparing checksums makes the push idempotent and avoids needless restarts.

Interview tip → Validate before reload; a bad config should never reach the running service.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation