Push an updated nginx config to a fleet, but only reload hosts where the file changed and the config validates.
IntermediateScenarioScenarios: deployments, user management and fleet operations
Answer
Situation read → Reloading unchanged hosts is noise; reloading with an invalid config takes the site down.
What I'd do →
for h in "${hosts[@]}"; do
remote_sum=$(ssh -n "$h" 'sha256sum /etc/nginx/conf.d/app.conf 2>/dev/null | cut -d" " -f1')
local_sum=$(sha256sum app.conf | cut -d' ' -f1)
[[ $remote_sum == "$local_sum" ]] && { echo "$h unchanged"; continue; }
scp -q app.conf "$h:/tmp/app.conf.new"
ssh -n "$h" 'sudo cp -a /etc/nginx/conf.d/app.conf /etc/nginx/conf.d/app.conf.bak 2>/dev/null;
sudo install -m 0644 /tmp/app.conf.new /etc/nginx/conf.d/app.conf &&
sudo nginx -t && sudo systemctl reload nginx ||
{ sudo mv /etc/nginx/conf.d/app.conf.bak /etc/nginx/conf.d/app.conf; exit 1; }' ||
{ echo "$h FAILED, restored previous config" >&2; exit 1; }
done
Why → Checksums make the operation idempotent; validation plus restore makes it safe.
Interview tip → Mention that this is what Ansible's template + validate: + handler notify gives you for free.
More on Scenarios: deployments, user management and fleet operations
Write the core of a deploy script with release directories, an atomic symlink switch and rollback.IntermediateDeploy to 10 servers behind an AWS ALB one at a time, removing each from the target group during its deploy. Outline the script.AdvancedAfter a deploy, the health check fails intermittently. Your script must roll back automatically, but only if the failure persists. How?IntermediateImplement a blue/green switch on a single nginx host with a script.AdvancedOnboard 30 engineers: create accounts and install their SSH keys from their GitHub usernames, idempotently.IntermediateAn engineer leaves the company. Write the offboarding steps for Linux servers.Intermediate