DevOps & Containers

Configuration Drift: How Servers Silently Diverge and How to Stop It

By NileVPS Team · Published · 4 min read

اقرأ المقال بالعربي

Two servers start life identical. Six months later, one has a hand-edited Nginx file, a package pinned to an older version, and a firewall rule someone added during an incident and never removed. Nobody remembers exactly what changed, and a deployment that works on one server fails on the other. This is configuration drift: the gap between the state you think your infrastructure is in and the state it is actually in. This article explains where drift comes from, how to detect it, and the habits that keep it from coming back.

Two kinds of drift

Configuration drift happens inside a server: files under /etc, installed packages, kernel parameters, cron jobs, users and services that differ from your intended baseline.

Infrastructure drift happens around the server: cloud resources such as firewall rules, DNS records, volumes or instances changed through a web console instead of through your infrastructure-as-code definitions.

Both share a root cause. A change was made outside the system that is supposed to be the source of truth.

Where drift comes from

  • Hotfixes under pressure. An SSH session at 2 a.m. to fix production, with no follow-up commit.
  • Automatic updates. Unattended upgrades on some servers but not others.
  • Manual console changes. Opening a port in the provider panel "just for a minute".
  • Snowflake servers. Long-lived machines configured by hand, step by step, over years.
  • Partial automation. Ansible manages Nginx, but PHP settings were tuned manually.

Why it matters

Drift turns predictable systems into unpredictable ones. Deployments fail in only one environment. Security baselines erode quietly, for example SSH password login re-enabled on a single host. Disaster recovery becomes guesswork, because rebuilding from your code produces a server that differs from the one you lost. Audits become painful because you cannot prove the actual configuration.

Detecting drift

Infrastructure: let Terraform tell you

If your resources are managed with Terraform or OpenTofu, a plan compares real-world state with your code:

terraform plan -refresh-only      # show what changed outside Terraform
terraform plan -detailed-exitcode # exit 0 = no changes, 2 = changes, 1 = error

The -detailed-exitcode flag makes it easy to run a scheduled drift check in CI and alert when the exit code is 2. For more background, see infrastructure as code with Terraform and Ansible.

Servers: Ansible check mode

Ansible can report what it *would* change without changing anything:

ansible-playbook site.yml --check --diff

Any task reported as changed represents drift from your playbook. Running this nightly against all hosts gives you a simple drift report.

Quick manual checks

When you have no automation yet, a few commands reveal a lot:

# Debian/Ubuntu: files in packages that differ from the shipped version
sudo debsums -c        # install with: apt install debsums

# RHEL family: verify installed packages
sudo rpm -Va

# compare installed packages between two servers
dpkg-query -W -f='${Package} ${Version}\n' | sort > pkgs-$(hostname).txt
diff pkgs-web1.txt pkgs-web2.txt

Keeping /etc under version control with a tool such as etckeeper also records every change with a timestamp.

Preventing drift

1. Make code the only path to change

Every change goes through Git: a playbook, a Terraform file, a Dockerfile. Console and SSH access remain for emergencies, and any emergency change is written back into code the same day.

2. Reconcile continuously

Running your configuration tool once at provisioning is not enough. Run it on a schedule so that manual edits are reverted or flagged. Pull-based tools and GitOps controllers do this automatically by comparing desired and actual state in a loop.

3. Prefer replacement over repair

With immutable infrastructure, you do not patch running servers; you build a new image and replace them. Containers apply the same idea at the application level: a rebuilt image is identical every time, so there is nothing to drift.

4. Restrict who can change what

Limit console access, use separate accounts, and keep an audit log. Fewer people with write access means fewer surprise changes.

5. Use snapshots as a safety net

Take a server snapshot before risky changes. It does not prevent drift, but it gives you a known-good point to return to while you fix your code.

Drift response checklist

StepAction
DetectScheduled terraform plan and ansible --check runs with alerts
DecideWas the change intentional? If yes, add it to code. If not, revert it
ReconcileApply the code so reality matches the definition again
LearnFind out why the change bypassed code and close that path

A VPS with snapshots and a cloud firewall managed from code is a good place to practice this discipline.

FAQ

Is all drift bad?

Not necessarily, but all drift should be visible. Sometimes a manual change is the right emergency fix. The problem is leaving it undocumented, so the next automation run either overwrites it or fails.

How often should I check for drift?

For production, daily is a reasonable starting point, plus a check before every deployment. Busy or regulated environments often run checks more frequently.

Do containers eliminate drift?

They remove most drift inside the application, because images are rebuilt from a Dockerfile. The host operating system, the orchestrator configuration and the cloud resources around it can still drift, so you still need checks there.

Related guides