What is infrastructure as code?

Infrastructure as code means describing servers, networks, DNS and configuration in text files kept under version control, and letting tools make reality match them. Changes become reviewed commits instead of commands typed at midnight.

What problem does infrastructure as code solve?

Snowflake servers. When systems are configured by hand, each one slowly becomes unique, nobody remembers why a setting exists, and rebuilding after a failure means guesswork. Writing the desired state in files gives a single source of truth: anyone can read how a server is built, changes are reviewed before they happen, history shows who changed what and why, and a new machine can be made identical to the last.

Declarative or imperative?

Declarative tools describe the end state, such as "this DNS record exists with this value", and work out the steps. Imperative tools describe the steps, such as "create the record, then reload". Declarative definitions are easier to reason about and re-apply safely; imperative scripts are more flexible for one-off sequences. Most teams combine both.

ToolStyleTypical scope
OpenTofu, TerraformDeclarative, with stateDNS records, cloud resources, certificates, monitoring checks
AnsibleMostly declarative modules, run in orderOperating system and application configuration
Salt, PuppetDeclarative, agent basedLarge fleets with continuous enforcement
cloud-init, shellImperativeFirst-boot steps and glue
Docker Compose, Kubernetes manifestsDeclarativeApplication containers

What is state, and why does it matter?

Tools like OpenTofu keep a state file that maps the resources in your code to real objects, such as a DNS record's ID at your DNS host. Planning compares code, state and reality and shows what will change before anything happens. The state can contain secrets, so store it encrypted in a backend with locking, never in the repository, and restrict who can read it.

tofu init -backend-config=backend-prod.hcl
tofu plan -out=release-142.plan
tofu apply release-142.plan

How do rented dedicated servers fit in?

In two layers. Ordering, payment and the operating system install happen in our console, after which the machine is an SSH-reachable host with your key. From there, configuration tools take over completely: Ansible roles for users, firewall, packages and services; container manifests for applications; OpenTofu for the DNS records, certificates and monitoring checks that point at the new machine. Record each server's model, location and IP addresses in the inventory file so the code knows what exists.

[web]
fra-web-01 ansible_host=203.0.113.81 model=essential-m
fra-web-02 ansible_host=203.0.113.82 model=essential-m
[db]
waw-db-01 ansible_host=198.51.100.33 model=business-2-2024

How should changes be reviewed?

Like application code. Every change is a pull request; automation runs syntax checks, linters and a plan or dry run, and posts the result for a reviewer. Only after approval does the pipeline apply it. Ansible's check mode and diff output, and OpenTofu's plan, make the effect visible before it happens.

ansible-lint roles/
ansible-playbook site.yml --check --diff --limit web

What is drift, and how is it caught?

Drift is any difference between the code and reality, usually from a manual fix that never made it back into the repository. Run plans and check-mode playbooks on a schedule and alert when they report changes. Then either fold the manual change into the code or let the tool revert it. Teams that tolerate drift slowly lose the benefits of the whole approach.

How do secrets stay out of the code?

Reference them rather than embed them. Ansible Vault, SOPS or a secrets manager such as OpenBao hold passwords, tokens and keys; the code names them and the pipeline decrypts them at run time. Rotate any secret that was ever committed in plain text, even if the commit was later removed.

Where do I start?

With the server you would least like to rebuild by hand. Write its configuration as a playbook, prove it by rebuilding a fresh machine to match, and move outwards from there. A small test machine such as ESSENTIAL-1 at $38.40 a month makes a good target for rebuild practice. Bare metal automation covers the wider workflow and First steps with a new server the first login.

Machines often used as automated fleet members

ModelProcessorCoresMemoryDrivesPortPer month
ESSENTIAL-1Intel Xeon-E 2386G632 GB2x 512 GB SSD NVMe1 Gbps unmetered$38.40
ESSENTIAL-SAMD Ryzen 7 9700X864 GB2x 512 GB SSD NVMe1 Gbps unmetered$46.20
ESSENTIAL-MAMD Ryzen 9 9900X1264 GB2x 512 GB SSD NVMe1 Gbps unmetered$70.80
BUSINESS-2 2024AMD EPYC 4344P864 GB2x 960 GB SSD NVMe3 Gbps unmetered$109.80

Related pages

Bare metal automation

Treat rented physical machines like code: unattended installs, cloud-init style first boot, configuration management, image pipelines and rebuild drills.

Read more

First steps with a new server

The first hour after delivery: log in, check the hardware matches the order, update, add a user, lock down SSH and set a firewall.

Read more

Hardening a new dedicated server

The first hour on a fresh machine: SSH keys, a firewall, automatic updates, brute force blocking and a habit of checking what listens.

Read more

CI runners and build farms

High clock Ryzen and many-core EPYC machines for CI runners, container builds and compile farms that finish faster.

Read more

Questions and answers

What is infrastructure as code?

Describing servers, networks and configuration in versioned files and letting tools make the real systems match them.

How do Terraform and Ansible divide the work?

Terraform or OpenTofu manage resources declaratively with a state file; Ansible configures operating systems and applications over SSH.

Can I manage rented dedicated servers as code?

Yes. Order and install from our console, then configure everything else with Ansible, containers and OpenTofu.

What is configuration drift?

Differences between the code and the real systems, usually from manual changes. Scheduled plans and check runs detect it.

Where should OpenTofu state be stored?

In an encrypted backend with locking and restricted access, never in the code repository, because it can contain secrets.