Back to blog

May 2026 · 6 min read

Ansible IaC Basics

A practical intro to Ansible, core IaC concepts, and a minimal playbook you can run today.

When teams configure servers by hand, small differences creep in over time. One machine has a missing package, another has an outdated config, and production starts behaving differently than staging.

Ansible helps solve this by describing infrastructure as code and applying the same desired state everywhere.

What is Ansible?

Ansible is an automation tool that connects over SSH and runs tasks on remote machines. You write human-readable YAML playbooks, and Ansible applies them in a repeatable way.

The core goal is simple:

  • define the desired state once,
  • apply it consistently,
  • reduce manual work and configuration drift.

IaC in one sentence

Infrastructure as Code (IaC) means your server setup lives in versioned files, not in undocumented manual steps.

That gives you:

  • repeatability,
  • auditability,
  • easier onboarding,
  • safer changes through review.

Core building blocks

  • Inventory: list of target hosts or groups.
  • Modules: reusable units like apt, service, copy, user.
  • Playbook: ordered tasks in YAML.
  • Idempotency: running the same playbook twice should not break anything; it only changes what is needed.

Basic example

A tiny setup that installs and starts Nginx on Ubuntu servers.

# inventory.ini
[web]
web-1 ansible_host=192.168.56.21 ansible_user=ubuntu
web-2 ansible_host=192.168.56.22 ansible_user=ubuntu
# webserver.yml
- name: Configure web servers
  hosts: web
  become: true
  tasks:
    - name: Install Nginx
      ansible.builtin.apt:
        name: nginx
        state: present
        update_cache: true

    - name: Ensure Nginx is running
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true

Run it:

ansible-playbook -i inventory.ini webserver.yml

What Ansible is especially good at

  • server bootstrap and baseline configuration,
  • package and service management,
  • configuration rollout across many hosts,
  • patch windows and routine maintenance,
  • simple deployments and operational runbooks.

Final takeaway

Ansible is strongest when your goal is consistent operations over many servers with minimal complexity. You describe the target state once, store it in Git, and let automation enforce it repeatedly.

That is the practical value of Ansible + IaC: fewer surprises, faster changes, and a more reliable infrastructure.