PracticeLabs
Week 10Lesson 1Required44 min estimated0% progress

Configuration Management and Infrastructure as Code

Explain why configuration management and infrastructure as code replaced box-by-box CLI, and separate Ansible, Terraform, Puppet, and Chef by agent model, push or pull, language, and state handling.

Lesson orientation

What you'll learn (6 objectives)~44 min: video → lesson → check → apply → lab prep

Learning objectives

  • State the problem configuration management and infrastructure as code solve, and define configuration drift
  • Distinguish declarative from imperative (procedural) change, and explain what idempotency guarantees
  • Separate agentless from agent-based tools, and push from pull, placing Ansible, Terraform, Puppet, and Chef correctly
  • Describe Ansible as agentless push automation driven by an inventory, playbooks, modules, and templates
  • Describe Terraform as declarative infrastructure as code that keeps a state file and converges through plan then apply
  • Recognise Ansible YAML and Terraform HCL on sight without authoring either

Terms you will see

Configuration managementInfrastructure as code (IaC)Configuration driftDesired stateDeclarativeImperative (procedural)IdempotencyAgentlessAgent-basedPush modelPull modelInventoryPlaybookTaskModuleTemplateHCLState file

Time breakdown

  • Read the notes30 min
  • Predict and check the file formats6 min
  • Automation-awareness exercise8 min

Assigned video

Opens on YouTube
Recommended video

Ansible, Puppet & Chef (Day 63 part 1)

By Jeremy's IT Lab · Opens externally on YouTube

Watch time not yet confirmed for this video — the notes below cover everything this lesson requires.

Where to stop

Stop once the agent model and the push/pull split are clear. Anything deeper on Puppet or Chef internals is past the exam's recognition depth, and Terraform is covered in the notes below rather than in this video.

No timestamps are assigned. The lesson's own segment bounds were never resolved in the source, so none are stated here rather than sending you to the wrong minute — a human still has to watch this video and record the exact range.

The link opens in a new browser tab. Return here when you finish watching.

Watch for these concepts

  • That nothing is installed on a managed device to use Ansible — the agentless claim, stated out loud
  • A playbook being described as a re-runnable statement of desired state, not a script of keystrokes
  • Puppet and Chef presented as the agent-based contrast, which is all this objective asks of them

Go beyond the video

The assigned video introduces the idea. CCNA Practice Labs completes the learning path: clarify core concepts, explore how each device behaves, visualize the communication path, check your understanding, and prepare for hands-on lab work.

Watch the concept → understand it → visualize it → practice it → apply it.

Why box-by-box configuration stops working

Everything you have configured in this course so far, you configured one device at a time: open a session, type the commands, verify, move on. That works for the four routers in a lab. It does not work for fifty. Setting one Network Time Protocol (NTP) server on fifty routers by hand is fifty sessions, fifty chances to mistype, and no record afterwards of who changed what or how to put it back.

Worse than the typing is what happens next. Someone fixes an outage at 2 a.m. and leaves a temporary command in place. A switch is replaced and its replacement is configured from memory. A push fails on three devices out of fifty and nobody notices. Slowly, devices that are supposed to be identical stop being identical. That divergence between what a device is actually running and what it is supposed to be running is called configuration drift, and its defining feature is that nothing announces it. You discover it when two supposedly identical switches behave differently.

Configuration management is the practice of defining a device's intended configuration in a file, storing that file the way software is stored — in version control, reviewed, diffable, revertible — and having a tool apply it repeatedly. Infrastructure as code (IaC) is the same idea taken one step further out: not just the configuration of devices that already exist, but the existence of the infrastructure itself, declared in files and built from them.

The exam framing for this whole lesson
Objective 6.6 is a recognition objective. You are asked to identify what these tools are and what they do — not to write a playbook, an HCL file, or a manifest. Aim for confident recognition: the shape of the file, the model behind the tool, and a one-line purpose for each. Everything below is pitched at exactly that depth.

Four ideas the tools are all built on

Before any tool names, learn the four vocabulary items every one of these tools shares. Questions about Ansible and Terraform are usually really questions about these.

Desired state is the first. Instead of describing the steps to take, you describe the condition you want to be true — "NTP server 10.0.0.1 is configured on every core router". The tool inspects the device, compares it to that statement, and works out for itself what, if anything, to change.

Declarative versus imperative is the second, and it is the same distinction named more formally. A declarative definition states the end state and leaves the route there to the tool. An imperative — also called procedural — definition states the sequence of operations: do this, then this, then this. A shell script that logs into a router and types commands in order is imperative. A file that says "this line should be present" is declarative. Terraform is fully declarative: you never order its resources, and it works out the dependency order itself. Ansible sits slightly to the imperative side of that line — each task declares a desired state, but the tasks in a play run top to bottom in the order you wrote them.

Idempotency is the third, and it is what makes declarative automation safe to re-run. An operation is idempotent when applying it twice leaves the same end state as applying it once. Run the automation on a device that already matches, and the tool changes nothing and reports "ok" or "unchanged". That is why these tools can be run on a schedule against production: a run that finds nothing to fix does nothing.

Configuration drift is the fourth, defined above. Idempotent automation is also the cure for it: because a re-run is harmless when nothing has changed, you can re-run continuously, and any device that has drifted is quietly pulled back to the declared state. A tool that reports what it would change without changing it — Ansible's check mode, Terraform's plan — turns the same mechanism into a drift detector.

A script is not configuration management
A Python or shell script that sends the same commands to fifty devices scales the typing, and that is genuinely useful — but it is imperative and usually not idempotent. Re-run it and it re-types everything, potentially duplicating configuration or failing on a device that has already been done. The step from scripting to configuration management is the step from "here are the keystrokes" to "here is the state I want".

Agentless or agent-based, push or pull

Two independent questions separate the tools, and the exam likes both. The first: does the managed device need extra software installed on it? A tool is agent-based when a piece of its own software — an agent — must be installed and running on every managed device. It is agentless when it does not, connecting instead over something the device already speaks: Secure Shell (SSH) on TCP 22, or a network management interface such as NETCONF on TCP 830 or RESTCONF over HTTPS.

The second: who starts the conversation? In a push model, a central control node initiates the connection and sends configuration out to the devices, when an operator or a pipeline says so. In a pull model, the agent on each device wakes up on a timer, contacts the central server, downloads its intended configuration, and applies it locally. Pull is self-healing by design — a drifted device is corrected at its next check-in without anyone asking — at the cost of needing that agent everywhere.

Agent model and direction, per tool
ToolAgent on the deviceDirectionHow it reaches the device
AnsibleNo — agentlessPushSSH, or a network API such as NETCONF / RESTCONF
TerraformNo — agentlessPushProvider plugins calling each platform's API
PuppetYes — agent-basedPullAgent checks in with the Puppet server, classically on TCP 8140
ChefYes — agent-basedPullchef-client on the node fetches from the Chef server over HTTPS
The single most tested fact in this lesson
To manage fifty Cisco routers with Ansible, what must you install on each router? Nothing. Ansible is agentless. If an answer option says an Ansible agent, a client, or a daemon must be running on the managed device, that option is wrong.

The four tools, side by side

The current CCNA 200-301 v1.1 blueprint names Ansible and Terraform. Puppet and Chef were named in the previous revision and are still worth recognising, because they are the agent-based, pull-model contrast that makes Ansible's model meaningful. Know them at name-and-model depth; you will not be asked to write a Puppet manifest or a Chef recipe.

The four configuration-management and IaC tools
ToolPrimary jobLanguageStylePersistent state file
AnsibleConfiguration management — configure things that already existYAML playbooksDeclarative tasks, run in the order writtenNo
TerraformInfrastructure as code — create, change, and destroy resourcesHCL (HashiCorp Configuration Language)Fully declarative; the tool derives the orderYes — this is its signature
PuppetConfiguration management, enforced continuouslyPuppet manifests (its own domain-specific language)DeclarativeNo — the server holds the catalogue instead
ChefConfiguration management, enforced continuouslyCookbooks and recipes written in RubyDeclarative resources inside procedural-looking RubyNo — the server holds the node data instead

Read that table by column rather than by row and the shape of the exam question appears. Ansible and Terraform are agentless and push; Puppet and Chef are agent-based and pull. Terraform is the only one of the four that keeps a persistent state file. Ansible is the only one whose files are plain YAML.

Ansible: inventory, playbook, task, module, template

Ansible runs from a control node — a machine with Ansible installed, which may be an engineer's laptop or a build server. It needs to know which devices it manages, and that list is the inventory: hosts, arranged into named groups, optionally with variables attached to a host or to a group. Referring to a group by name in a playbook is how one file targets forty switches.

An inventory, in YAML form — the list of what is managed
all:
  children:
    routers:
      hosts:
        r1.campus.example:
        r2.campus.example:
      vars:
        ntp_server: 10.0.0.1

A playbook is the file describing what should be true. It contains one or more plays; a play targets a group from the inventory and contains a list of tasks; each task calls a module, which is the unit of code that knows how to inspect a device and bring one thing into the desired state idempotently. `cisco.ios.ios_config` is a module. So is `user`, and `file`, and several thousand others.

A playbook — read it, do not author it
# site.yml — ensure NTP is configured on every router in the inventory
- name: Configure NTP on core routers      # a play
  hosts: routers                            # a group from the inventory
  gather_facts: false
  tasks:
    - name: Add NTP server                  # a task
      cisco.ios.ios_config:                 # the module that does the work
        lines:
          - ntp server 10.0.0.1             # the line that should be present

Run that today and the line is added. Run it again tomorrow and Ansible reports ok with no change, because the module checks before it writes. That is idempotency in practice, and it is why the same playbook can safely run nightly.

A template is the last piece, and it is what stops one playbook per device. A template is a configuration file containing placeholders instead of literal values; the tool fills those placeholders from variables at run time to produce the finished configuration for each device. Ansible uses the Jinja2 templating language for this, and template files conventionally end in `.j2`. One template plus per-host variables from the inventory produces forty correct, individual configurations from one reviewed source file.

A fragment of a Jinja2 template and what it renders
# banner.j2 — the template
hostname {{ inventory_hostname }}
ntp server {{ ntp_server }}

# rendered for r1.campus.example
hostname r1.campus.example
ntp server 10.0.0.1
Recognising YAML
Two-space indentation, key: value pairs, and list items beginning with a hyphen. Indentation is structure, not decoration — a task indented under the wrong key belongs to the wrong thing and silently never runs. Ansible playbooks and inventories are YAML; so are many other tools' configuration files, so YAML alone does not prove Ansible. A module name such as ios_config does.

Terraform: HCL, the state file, plan then apply

Terraform, from HashiCorp, is the infrastructure-as-code tool of the pair. You write HCL — HashiCorp Configuration Language — declaring the resources that should exist. You never write the order in which to build them; Terraform reads the references between resources, builds a dependency graph, and works the order out.

HCL — declaring that a resource should exist
# main.tf
resource "example_network" "campus" {
  name = "campus-core"
  cidr = "10.10.0.0/16"
}

The state file is what makes Terraform different from everything else in this lesson. It is a record Terraform keeps of the resources it has actually built and their current known properties. On every run, Terraform compares three things: your declaration, the state file, and reality as reported by the platform's API. From that comparison it produces a plan — the precise list of resources to add, change, or destroy in order to converge. `terraform plan` shows you that list and changes nothing; `terraform apply` carries it out.

The signature workflow
terraform plan     # show the difference between declaration, state file, and reality
terraform apply    # converge: create, update, or destroy to match the declaration

That three-way comparison is also Terraform's drift detection. If someone changes a managed resource by hand, the next plan shows it as a difference from the declaration, and the next apply corrects it. Because the state file records what already exists, Terraform can also tell the difference between "build this" and "this is already built", which is what stops it recreating infrastructure on every run.

Recognising HCL
resource "type" "name" { key = value } — braces for blocks, and an equals sign for assignment. YAML has neither. If you see = and { }, think HCL and Terraform; if you see key: value and hyphenated list items, think YAML and Ansible.

What you should retain

  • Configuration management and infrastructure as code replace box-by-box CLI with reviewed, version-controlled, repeatable files.
  • Configuration drift is the silent divergence of a device from its intended configuration; idempotent automation both detects and corrects it.
  • Declarative states the end condition and lets the tool find the route; imperative (procedural) states the sequence of steps.
  • Idempotency means a second run changes nothing — which is what makes running automation on a schedule safe.
  • Ansible: agentless, push, YAML playbooks over SSH or a network API, driven by an inventory, using modules and Jinja2 templates. No state file.
  • Terraform: agentless, push, declarative HCL, keeps a state file, converges with plan then apply, detects drift from that state.
  • Puppet and Chef: agent-based and pull. An agent on each device checks in with a central server and applies its configuration locally.
  • Recognition tells: YAML is key: value with hyphenated lists; HCL is braces with equals signs.
Pause and predictNot scored — nothing is recorded

Before you read on

Ansible and Terraform are both agentless and both push. Name the one behavioural difference the exam cares most about — the thing Terraform maintains that Ansible does not — and say what that thing lets Terraform do.

Interactive tool
Recommended~8 min

Automation Sandbox

Core path. Run the YAML and HCL recognition drills until you can name the tool from a three-line snippet without reading it twice — that speed is exactly what objective 6.6 tests, and it is the one thing prose cannot rehearse for you.

Apply

From one manual change to an automated one

An engineer has fixed a problem by hand: they opened a session to a single core router and typed `ntp server 10.0.0.1`. Forty-nine other routers still need it. Work through how that becomes an automated, re-runnable change — this is the awareness depth objective 6.6 asks for, and it needs no lab topology.

Step 1 of 4

Which Ansible construct answers the question "which devices does this change apply to?"

Section quiz

Check this section before moving on

Required8 questions~10 min

Configuration Management & IaC

The quiz opens on its own page so you can focus on it. It is a Week 1 milestone, tracked separately from this lesson's own completion.

Topics covered

  • Configuration drift and what makes automation idempotent
  • Declarative versus imperative change
  • Agentless versus agent-based, push versus pull
  • Ansible's inventory, playbooks, modules, and templates
  • Terraform's state file and the plan-then-apply cycle
  • Telling YAML and HCL apart on sight
Start the quiz

Study deeper

Topic guides extend this lesson — they do not replace the first-party walkthrough above.

Automation & APIs

For the fuller configuration-management tool comparison and the wider automation workflow these tools sit inside