---
title: "Replace servers instead of patching them · Agent Wranglers"
url: https://agentwranglers.se/playbook/infrastructure/servers/immutable-servers
updated: 2026-10-20
licence: "All rights reserved"
---

# Replace servers instead of patching them

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Servers](https://agentwranglers.se/playbook/infrastructure/servers)
- Rule: 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: 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, so the newest updates are always baked in. This rule does not fit one long-lived server. Use [configuration management](https://agentwranglers.se/playbook/infrastructure/servers/configuration-management) for that instead.
- Check: No running server is older than 30 days. Every server runs the image ID of the latest build.

Example:

```hcl
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 }
  }
}
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers infrastructure playbook: https://agentwranglers.se/playbook/infrastructure/servers/immutable-servers`.

- Next: [Configure long-lived servers from code](https://agentwranglers.se/playbook/infrastructure/servers/configuration-management)
- [Servers](https://agentwranglers.se/playbook/infrastructure/servers)
