DevOps / Ansible Interview questions
Explain the execution flow of a rolling update using serial?
serial splits a play's target hosts into smaller batches and runs the entire play (all its tasks and handlers) to completion for one batch before starting the next, instead of running each task against every host at once.
- hosts: webservers serial: 2 max_fail_percentage: 20 tasks: - name: Deploy new app version ansible.builtin.command: /opt/deploy.sh - name: Health check ansible.builtin.uri: url: "http://{{ inventory_hostname }}/health" register: health until: health.status == 200 retries: 5
With serial: 2, only 2 hosts are taken through the whole play at a time - deploy, health check, and any handlers - before the next 2 hosts start, keeping the majority of the fleet serving traffic throughout the rollout. max_fail_percentage adds a safety valve: if failures across completed batches exceed that threshold, Ansible stops starting new batches rather than continuing to roll a broken change out to the entire fleet. serial can also take a list (e.g. [1, 5, "100%"]) to start with a small canary batch and progressively widen, which is a common pattern for cautious production rollouts.
More Related questions...