Network Bytes · Episode 67 · CCNA 6.6
"Ansible vs Terraform"
Terraform builds infrastructure from a file that describes what should exist, and Ansible logs in to existing devices and runs a playbook of tasks on them. Each can do some of the other's job, and many teams use both.
Build, then set up
Picture a new office. First someone builds the rooms; then a crew moves in and sets up the desks and the router. Network automation tools often split the same way. Some tools are best at provisioning: making things exist, such as cloud networks, servers and firewalls. Others are best at configuration management: changing settings on things that are already running. The CCNA asks you to recognize what each kind of tool can do.
Terraform: describe what should exist
With Terraform you write configuration files that describe the desired state, for example "one network, two servers, one firewall". This style is called declarative: you say what you want, not the steps to get there. Terraform keeps a state file that records what it built last time. When you run it, it compares your files with what is really there, shows a plan of the differences, and then applies only those changes. It talks to clouds and other platforms through providers, which are plug-ins that know each platform's API. This is infrastructure as code: the file is the source of truth, and you can review it and keep it in version control like any other code.
Ansible: log in and run the tasks
Ansible works on devices that are already running. It is agentless: nothing extra has to be installed on the routers or servers it manages. It connects from a control machine, usually over SSH (for some network platforms over HTTPS, NETCONF or a vendor API), and pushes changes. The work is written in a playbook, a YAML file with an ordered list of tasks, such as "add a user", "set VLAN 10" and "save the config". The same playbook can run against one device or hundreds, listed in an inventory.
Mostly, and often both
"Builder vs setup crew" is a simplification. Terraform can manage some device settings through providers, and Ansible has modules that create cloud resources. In practice many teams use both: Terraform to create the infrastructure, then Ansible to configure what is inside it.
Try it yourself
Ansible's favorite way in is SSH, and most computers already have an SSH client. Open a terminal (Terminal on a Mac, PowerShell on Windows 10 or later) and type ssh -V. It prints the version of the SSH client installed on your machine. Then write a three-line "wanted" list for your own desk, such as "laptop, charger, notebook", look at what is really there, and note the difference. That compare-then-fix habit is exactly what Terraform's plan step does.
Good to know
- CCNA 6.6: recognize the capabilities of configuration management mechanisms such as Ansible and Terraform.
- Terraform (made by HashiCorp, now part of IBM) is declarative infrastructure as code: config files describe the desired state, a state file records what exists, and Terraform plans the difference and applies it through provider APIs. It can also manage some network device settings through providers.
- Ansible (Red Hat) is agentless and push-based. It connects over SSH, or HTTPS, NETCONF or APIs for some network platforms, and runs YAML playbooks of tasks. It can also provision cloud resources.
- "Builder vs setup crew" is our simplification, flagged in the video with "often both".
- The task names in the video ("add user", "set VLAN 10", "save config") are examples.
For CCNA learners
This lines up with CCNA 200-301 exam topic 6.6, recognize the capabilities of configuration management mechanisms such as Ansible and Terraform: know that Terraform declares a desired state and provisions to match it, and that Ansible is agentless, pushes changes over SSH and uses playbooks of tasks.
Answer to the comment question
Ansible. The 50 routers already exist, so nothing needs building; they just need the same setting changed. That is the setup crew's job: one playbook with a task that sets the time server to 10.0.0.1, pushed over SSH to all 50 routers, with no extra software installed on them. Terraform could manage some router settings through a provider, but it is built for creating and tracking infrastructure, so Ansible fits best here.
Test your knowledge
Quick quiz: "Ansible vs Terraform"
4 multiple-choice questions. Pick one answer for each, then check how you did.
Sources
- Ansible documentation, "Network Getting Started": agentless automation for network devices over SSH or HTTPS; playbooks
- HashiCorp, "What is Terraform?": infrastructure as code; declarative configuration; providers; state
- Network Lessons, "Terraform Explained": CCNA 200-301 lesson, Terraform provisions and compares desired vs current state
- Cisco, CCNA 200-301 v1.1 exam topics: 6.6 recognize the capabilities of configuration management mechanisms such as Ansible and Terraform
Video transcript
Ansible or Terraform: which one should you use?
Picture a new office. First, someone builds the rooms. Then a crew moves in and sets everything up.
Terraform is the builder. You write a file describing what should exist, like cloud networks, servers and firewalls. Terraform compares it to what's there, and creates or changes things to match.
Ansible is the setup crew. It logs in to devices that already exist, usually over SSH, and runs a list of tasks called a playbook. No extra software needed on them.
One builds, one configures. Mostly. Each can do some of the other's job, and many teams use both.
You need the same time server setting on 50 routers that already exist. Which tool fits best? Comment your answer below!
That's your byte.
More from Network Bytes
- EP65"REST APIs for network engineers"
- EP66"Reading JSON in 60 seconds"
- EP68"AI and ML in network operations"
- EP69"Ping: testing reachability"