PikoSystem IT engineering services
DevOps

Infrastructure as Code with Terraform and Ansible

A server configured by hand a few years ago usually has no documentation, and rebuilding it is guesswork. With Infrastructure as Code, configuration lives in Ansible and Terraform, sits in Git and gives the same result every run. We write that code from the servers you already have.

Tools & technology infrastructure-as-code
  • Terraform
  • Ansible
  • Packer
  • cloud-init
  • Proxmox VE
  • VMware vSphere
  • GitLab CI
  • Molecule
5work areas
4deliverables
4steps

What is Infrastructure as Code?

Infrastructure as Code is the practice of defining server settings, virtual machines, networks and DNS records as code in tools like Ansible and Terraform, so the configuration lives in Git and gives the same result every run. It is needed when nobody knows what has been configured on the servers, each new server takes a day of manual setup, identical servers have drifted apart, or a lost server couldn't be rebuilt. PikoSystem captures the current state of your servers, writes Ansible roles for baseline hardening, Nginx and PHP installs and SSH key management, defines Proxmox or vSphere VMs and DNS in Terraform, and runs changes from CI with review before apply. Playbooks run in check mode on a low-risk server first. You receive a Git repository of playbooks, roles and modules, a README and a drift report.

When you need Infrastructure as Code

  • We don't know exactly what has been configured on our servers.
  • Every new server takes a day of manual setup.
  • Servers that should be identical have drifted apart.
  • If a server died, we're not sure we could rebuild it.

What Infrastructure as Code includes

01

Capture current state

We record server settings, installed packages, users, firewall rules and services as the baseline for the code.

02

Ansible roles

Roles for repeat work such as baseline hardening, Nginx and PHP installs, and user and SSH key management, with a separate inventory per environment.

03

Terraform for resources

Proxmox or vSphere virtual machines, networks and DNS records defined in Terraform, with state stored in a secure backend.

04

VM templates

Templates built with Packer and cloud-init, so a new machine comes up with its baseline configuration and no manual OS install.

05

Pipeline-driven changes

terraform plan and ansible-playbook run from CI with review before apply, so no change reaches a server without a record in Git.

What you get from Infrastructure as Code

  • A Git repository with playbooks, roles and Terraform modules
  • A README for running each playbook and adding new servers
  • A drift report comparing servers with the desired state
  • A training session for your operations team

Infrastructure as Code: a practical guide

Where should Terraform state live?

Terraform records what it has built in terraform.tfstate, and that file holds passwords and other sensitive values in plain text. Committing it to Git is one of the most common mistakes. If two people run terraform apply at once without state locking, the file can be corrupted and Terraform loses track of what it manages.

For small teams, GitLab's managed Terraform state backend is the simplest choice, with locking and versioning built in. Otherwise we set up an S3 backend on an internal MinIO with locking enabled. Resources created by hand earlier are brought under management with terraform import or an import block, so nothing needs rebuilding.

Ansible AWX or playbooks from the pipeline?

AWX is the open source project behind Ansible Automation Platform. It adds a web UI, per-team access control, scheduled runs, a credential store and a history of every job. The trade-off is that AWX is itself a service, installed on Kubernetes with the AWX Operator, and it needs upgrades and care.

If your team is small and every change goes through a merge request, running ansible-playbook from GitLab CI is enough and adds nothing new to maintain. AWX earns its place when people outside engineering, such as a support desk, need to run specific playbooks without direct server access.

Common server configuration automation mistakes

Leaning on the shell and command modules instead of purpose-built Ansible modules makes playbooks non-idempotent, so a second run repeats changes or fails. Passwords typed straight into group_vars should be encrypted with ansible-vault or kept in Vault.

Pin your versions too: collections in requirements.yml and providers in .terraform.lock.hcl, which belongs in Git. The biggest problem is human, though. If people keep making changes over SSH after the code exists, servers and code drift apart again. A scheduled playbook run in check mode surfaces that drift early.

What determines the size of an IaC project?

The number of distinct server roles matters more than the number of servers. Twenty identical web servers need one role; five servers that each do something different need five. Operating system variety adds work as well, since supporting Ubuntu, AlmaLinux and Windows together takes longer than a single distribution.

Other factors: whether your hypervisor or cloud provider has a usable API, whether CI and Git are already in place, how much documentation exists, and whether secrets management has an answer yet. We agree the scope once servers and resources are listed.

How Infrastructure as Code works

  1. 01

    Inventory and priorities

    We list your servers and resources and agree with you which parts to codify first.

  2. 02

    Write and test

    We write the roles and modules and test them in a lab using Molecule or throwaway VMs.

  3. 03

    Staged rollout

    We run in check mode on a low-risk server first, review the differences, then move on to the rest.

  4. 04

    Handover

    You get the repository and documentation, and we practise day-to-day runs with your team.

Infrastructure as Code: frequently asked questions

Our infrastructure is small. Do we need IaC?

With one or two servers, a simple Ansible playbook that documents and rebuilds them is enough and doesn't take long. Terraform and pipeline-driven runs pay off once you have more servers or frequent changes.

Does Terraform work with Proxmox and local cloud providers?

There are maintained providers for Proxmox and VMware. Some local cloud providers offer a provider or a usable API, and for the rest we drive the API from Ansible. We check support for your environment before starting.

Is it risky to automate configuration on live servers?

It can be if done carelessly. That's why we run playbooks with --check and --diff first, review the changes with you, and apply them in an agreed window.

Related searches

  • Infrastructure as Code
  • Ansible
  • Terraform
  • infrastructure automation
  • server configuration automation

Quote

Tell us what you need, we'll come back with a plan and a price

A few lines on where things stand and what you want is enough. An engineer calls you back, not a sales rep.

  1. 01We read your request and call if anything is unclear.
  2. 02If needed, we do a quick remote review or a site visit.
  3. 03You get a written proposal with scope, timeline and cost.

Your details are only used to answer this request.