Week 10Network Assurance38 min

Ansible and Terraform Overview

Learning objectives

  • Compare Ansible agentless automation with Terraform declarative IaC
  • Identify playbooks, tasks, modules, and inventory in Ansible
  • Explain Terraform state and provider concepts at CCNA depth
  • Choose the right tool for config push vs infrastructure provisioning

Watch first

Recommended video

Ansible, Puppet & Chef (Day 63 part 1)

Video credit: Jeremy's IT Lab

Watch on YouTube
Recommended video

Terraform & Infrastructure as Code (Day 63 part 2)

Video credit: Jeremy's IT Lab

Watch on YouTube

Plain-English explanation

Ansible automates configuration using playbooks (YAML) — SSH to devices, run modules (tasks), no agent on network gear. Great for pushing VLANs, ACLs, or NTP to many routers at once.

Terraform is declarative Infrastructure as Code — you describe desired resources in .tf files; Terraform providers talk to APIs and maintain state showing what exists vs what you declared.

Both reduce manual CLI — different sweet spots: Ansible excels at day-2 config; Terraform at provisioning cloud/VPN/VLAN objects via APIs.

Deep dive

Ansible components:

| Term | Role | |------|------| | Inventory | List of hosts/groups | | Playbook | Ordered plays | | Task | One module invocation | | Module | idempotent unit (ios_config, ios_vlan) | | Jinja2 | Templating variables |

Sample task (conceptual):

- name: Configure NTP
  cisco.ios.ios_config:
    lines:
      - ntp server 203.0.113.1

Terraform flow: Write config → terraform plan (preview diff) → terraform apply (execute) → state file tracks reality.

Puppet/Chef (awareness): Agent-based server automation — CCNA may mention comparatively; Ansible agentless is emphasized.

Step-by-step — when to use which

Scenario 1: Push consistent SNMP config to 100 switches nightly → Ansible playbook + Git.

Scenario 2: Provision AWS VPC + subnets via code in CI pipeline → Terraform.

Scenario 3: One-off lab VLAN on three switches → CLI or small Ansible — Terraform overkill.

Commands to know

Ansible (conceptual)

ansible-playbook -i inventory.yml ntp.yml ansible all -m ping -i inventory.yml

Terraform (conceptual)

terraform init terraform plan terraform apply

Troubleshooting

| Issue | Tool hint | |-------|-----------| | Playbook changes not idempotent | Wrong module — use ios_config not raw command | | Terraform wants destroy/recreate | State drift — import or fix outside TF | | SSH works manually, Ansible fails | Inventory host key, become, creds vault | | Provider auth fail | API token scope or expired cert |

Version-control playbooks and .tf files — rollback is a git revert, not panic CLI.

Exam relevance

Exam trap

Ansible is agentless for network devices (uses SSH/NETCONF/API). Do not pick "requires agent on every router" for Ansible.

Idempotency

Running the same Ansible play twice should not duplicate config lines — modules enforce desired state.

Practice checklist

  • Label Ansible inventory, playbook, task, module from a sample
  • Explain Terraform plan vs apply in one sentence each
  • Compare Ansible push model vs Terraform declarative model
  • Name one network module/use case for Ansible
  • Explain why state file matters in Terraform

Which tool is primarily agentless and uses YAML playbooks?

What does 'terraform plan' show?

Video credits

These are free, open educational videos from independent creators. We link and embed them with attribution; all rights belong to the respective channels.