Use Ansible to perform a rolling restart of an application service across an inventory group with serial batching and pre/post health checks

domain: docs.ansible.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Set serial: "25%" (or a list like [1, 5, "100%"]) in the play header so Ansible processes hosts in batches rather than all at once
  2. Add a pre_tasks block that checks service health before the rolling action: use uri module to hit the health endpoint and register the result, failing the play if status != 200
  3. Use the systemd or service module to restart the target service: name: myapp state: restarted
  4. Add a post_tasks block that waits for the service to return healthy: use wait_for_connection or uri with retries and delay, then assert the expected response
  5. Set max_fail_percentage: 0 in the play to abort the entire rolling restart if any host in a batch fails its health check, preventing a bad restart from propagating
  6. Run with ansible-playbook rolling_restart.yml -i inventory/prod --check first for a dry run, then without --check for the live execution

Known gotchas

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans