The Cost of Maintenance Outages
Traditionally, deploying updates meant taking application servers offline, rendering services unavailable to users during release windows.
Ansible playbooks solve this by orchestrating rolling deployments, updating servers sequentially without downtime.
DevOps Principle: Automate deployments so they occur during normal business hours. The user should never see a service error page during updates.
Implementing Rolling Deployments
Ansible playbooks coordinate rolling updates using the serial keyword, limiting the number of target servers updated concurrently:
# Zero-downtime rolling deployment playbook in Ansible 1.4
- name: Rolling Deploy
hosts: webservers
serial: 1 # Deploy updates one server at a time
tasks:
- name: Remove server from load balancer pool
local_action: command /usr/bin/disable_node.sh {{ inventory_hostname }}
- name: Update application code
git:
repo: git@github.com:shivam-itcs/app.git
dest: /var/www/app
version: release-1.2.0
- name: Restart application server
service:
name: webapp
state: restarted
- name: Verify application health
wait_for:
port: 80
delay: 5
- name: Re-add server to load balancer pool
local_action: command /usr/bin/enable_node.sh {{ inventory_hostname }}Rollback Automation
If automated health checks fail, the playbook aborts execution, leaving the remaining servers operational in their last stable state, ensuring high system reliability.