Lesson 5 of 7 · Automation

IaC and Configuration Management

Infrastructure as code versus configuration management, Terraform versus Ansible, and how they're used together.

Beginner 5 sections 3 min read

Two different jobs

Infrastructure as code (IaC) tools, such as Terraform, create the infrastructure: networks, servers, disks, and cloud databases. Configuration management tools, such as Ansible, set up what runs on it: operating system settings, database software, parameters, and users. Most automation uses both, one after the other.

CHANGECONFIGUREPROVISION CI/CD withLiquibase, Flywayconfigurationmanagement: Ansibleinfrastructure ascode: Terraform Schema changes tables, indexes, grants, migrations Software and settingsInfrastructure OS settings, Oracle install, parameters, users, patchesnetwork, virtual machines, disks, cloud databases day 2:ongoingday 1 andday 2mostlyday 1

Teams often talk about day 0 (design), day 1 (build and deploy), and day 2 (operate: patch, change, scale). Terraform's work is mostly day 1; Ansible and CI/CD carry on through day 2, for as long as the database runs.

Terraform and Ansible compared

Terraform (infrastructure as code)Ansible (configuration management)
Main jobCreate, change, and destroy infrastructureConfigure servers and software, and run operational tasks
StyleDeclarative: describe what should existTask-based playbooks, mostly with declarative, idempotent modules
How it knows what existsA state file records everything it managesChecks each server live, every time it runs
Talks toCloud and platform APIs: OCI, AWS, Azure, VMwareServers over SSH (or WinRM for Windows), plus some APIs
Previewterraform planansible-playbook --check --diff
LanguageHCL (HashiCorp Configuration Language)YAML
DBA examplesA DB server and its disks, an Autonomous Database, an RDS instanceInstalling Oracle, patching, setting parameters, creating users, refreshes

Here's the same database server seen through each tool. Terraform describes the server that should exist:

# Terraform (HCL): a database server should exist, with this shape
resource "oci_core_instance" "db01" {
  display_name = "kofi-db01"
  shape        = "VM.Standard.E5.Flex"
  shape_config {
    ocpus         = 2
    memory_in_gbs = 32
  }
  # ...compartment, subnet, and image...
}

Ansible then describes how that server should be set up:

# Ansible (YAML): what should be true on the server
- hosts: db_servers
  become: true
  roles:
    - os_baseline       # kernel settings, packages, the oracle user
    - oracle_install    # Oracle software in /u01
    - oracle_db         # the database, parameters, users, backups

Where they overlap

The line isn't perfectly sharp. Ansible can create cloud resources, and Terraform can run simple setup scripts when a server starts. But each tool is strongest at its own job, and using the wrong one causes pain: Ansible doesn't track infrastructure the way Terraform's state does, and Terraform isn't built for ongoing changes inside a server. The common pattern is Terraform to build, Ansible to configure, run in sequence by a pipeline, as in Git in Practice.

For managed cloud databases, such as Autonomous Database or Amazon RDS, there's no server to configure, so Terraform often does most of the work, with SQL migrations through CI/CD for the schema.

Other tools you'll meet

Infrastructure as codeConfiguration management
OpenTofu, the open source fork of TerraformPuppet
AWS CloudFormation, Azure Bicep, OCI Resource ManagerChef
Pulumi, which uses programming languages such as PythonSalt

The next two modules in this path cover Terraform and Ansible in depth.

Key takeaways

  • Infrastructure as code builds the infrastructure; configuration management sets up what runs on it.
  • Terraform is declarative, tracks what it manages in a state file, and previews changes with terraform plan.
  • Ansible runs YAML playbooks over SSH, with idempotent modules, and previews with --check.
  • Terraform is mostly day 1; Ansible and CI/CD carry on through day 2.
  • The usual pattern: Terraform builds, Ansible configures, and CI/CD applies schema changes, all from one pipeline.