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 →
- Compute local SHA-256; on each host run
sha256sumon the remote file via Fabric. - If different:
c.put()to a temp path, validate (nginx -t -c ...),sudo mvinto place,sudo systemctl reload. - Roll through hosts in batches and stop on the first failure.
- 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.
More on Kubernetes, Docker, SSH & fleet automation
You need a report of every pod in the cluster with no CPU or memory limits. How do you write it?BeginnerYou are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?AdvancedYou need to restart all Deployments in a namespace that reference a rotated Secret. How?AdvancedYour CI runners keep running out of disk because of Docker images. Write a cleanup plan in Python.IntermediateYou need to run `df -h` on 300 Linux hosts and list any above 85%. Python or Ansible?BeginnerA Python script SSHes to hosts with `AutoAddPolicy`. Security says that is unacceptable. What do you change?Intermediate