Agent Wranglers

INF-43Recommended

Replace servers instead of patching them

Build a new machine image for every change, start new servers from it and stop the old ones. Never change a running server by hand.

How to do it

Build the image in CI with a tool such as Packer, or ship a container image. Start the new servers, wait for their health checks, then stop the old ones. A server changed by hand drifts away from the code, and nobody can rebuild it the same way. Replace each server at least every 30 days. Also roll out a new image within the time limit set by Install security updates by themselves requires. This rule does not fit one long-lived server. Use configuration management for that instead. Build each image the same way every time, as Make builds repeatable says.

Examples

Terraform example

resource "aws_launch_template" "web" {
  image_id      = data.aws_ami.web_latest.id
  instance_type = "t4g.small"
}

resource "aws_autoscaling_group" "web" {
  min_size = 2
  max_size = 6
  launch_template {
    id      = aws_launch_template.web.id
    version = aws_launch_template.web.latest_version
  }
  instance_refresh {
    strategy = "Rolling"
    preferences { min_healthy_percentage = 100 }
  }
}

How to check

No running server is older than 30 days. Every server runs the image ID of the latest build.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/servers/immutable-servers">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.