Configuration Management & Infrastructure as Code (IaC)
Core Concepts
- Configuration Drift: When individual, unrecorded changes made over time cause a device’s configuration to deviate from the company’s standard and correct baseline configurations.
- Configuration Provisioning: The process of applying configuration changes to devices, including the initial setup of new devices. Traditional manual provisioning (SSH/Console) does not scale well in large networks.
- Templates and Variables: Essential components of automation tools.
- Template: A configuration file with placeholders (variables) instead of static values (e.g., hostname, IP address).
- Variables: A separate file specifying the unique values for a specific device, which are substituted into the template to generate the final configuration.
These tools facilitate centralized control of large numbers of network devices. While originally developed for server/VM automation, they are now widely used for network devices.
Ansible
- Language: Written in Python. Configuration files use YAML. Templates use Jinja2.
- Architecture: Agentless. Does not require special software on managed devices.
- Communication Model: Push model. The control node connects to devices via SSH to push configurations.
- Key Files:
- Playbooks: The “blueprint” of automation tasks, outlining logic and actions (YAML).
- Inventory Files: List managed devices and their characteristics/roles (INI or YAML).
- Templates: Configuration files with variable placeholders (Jinja2).
- Variable Files: List variables and their values to substitute into templates (YAML).
Puppet
- Language: Written in Ruby. Uses a proprietary language for its files (not YAML).
- Architecture: Typically Agent-based (requires a Puppet agent on the managed device). Can be run agentless via an external proxy agent using SSH.
- Communication Model: Pull model. Managed devices connect to the server to receive configurations.
- Server Name: Puppet Master.
- Port: Clients communicate with the Puppet Master via TCP 8140.
- Key Files:
- Manifests: Define the desired configuration state of a network device.
Chef
- Language: Written in Ruby. Uses a Domain-Specific Language (DSL) based on Ruby.
- Architecture: Agent-based (requires a Chef agent on the managed device).
- Communication Model: Pull model.
- Port: Chef server uses TCP 10002 to send configurations to clients (among other ports).
- Key Files:
- Resources: Define configuration objects managed by Chef (the “ingredients”).
- Recipes: Outline the logic and actions performed on resources.
- Cookbooks: Sets of related recipes grouped together.
- Run-lists: An ordered list of recipes executed to bring a device to the desired state.
Infrastructure as Code (IaC) Concepts
- Infrastructure as Code (IaC): The practice of provisioning and managing infrastructure (servers, networks, cloud resources) using machine-readable configuration files/code instead of manual CLI/GUI configuration.
- Configuration Management vs. Provisioning:
- Configuration Management (Ansible, Puppet, Chef): Manages existing infrastructure by installing software, configuring settings, and maintaining system state.
- Infrastructure Provisioning (Terraform): Creates, modifies, and deletes infrastructure resources from scratch (e.g., spinning up VMs or cloud routers).
Mutable vs. Immutable Infrastructure
| Approach |
Description |
Typical Tool |
| Mutable |
Infrastructure can be modified in place after deployment (e.g., applying patches or config changes to an existing VM). |
Configuration Management (Ansible) |
| Immutable |
Infrastructure cannot be changed after deployment. Updates require replacing the old resource with a new, updated instance, then destroying the old one. Eliminates configuration drift. |
Provisioning (Terraform) |
Procedural vs. Declarative Approaches
| Approach |
Description |
Focus |
Example Tools |
| Procedural (Imperative) |
Follows explicit, ordered steps defined by the engineer to achieve the desired outcome. Requires knowing exact commands and order. |
How to make changes |
Ansible, Chef |
| Declarative |
Defines the desired end state. The tool automatically figures out the necessary steps and order to achieve that state. |
What the final state should be |
Terraform, Puppet |
- Overview: An open-source IaC provisioning tool developed by HashiCorp.
- Language: Terraform Core is written in Go. Configuration files are written in HashiCorp Configuration Language (HCL), a Domain-Specific Language (DSL).
- Architecture: Agentless and uses a Push model (similar to Ansible).
- Providers: Platforms on which infrastructure is deployed (e.g., AWS, Azure, GCP, Kubernetes, Cisco Catalyst Center, Cisco ACI, Cisco IOS XE). Terraform interacts with these via their APIs.
- Key Components:
- Terraform Core: The main software that processes configurations and interacts with providers.
- Configuration Files: Define the desired end state declaratively (HCL).
- State File: Tracks the current state of the deployed infrastructure to compare against the desired state.
- Providers: The target platforms.
graph LR
A[Write] -->|Define desired state in HCL| B[Plan]
B -->|Analyze and preview changes| C[Apply]
C -->|Execute changes via APIs| D[Infrastructure]
D -.->|Track current status| E[(State File)]
- Write: Define the desired end state of infrastructure resources in configuration files.
- Plan: Terraform analyzes the files and shows exactly what changes will be made for review.
- Apply: Terraform executes the plan to provision/manage the resources. (Optional 4th step: Destroy to delete unneeded resources).
Comprehensive Comparison Table
| Feature |
Ansible |
Puppet |
Chef |
Terraform |
| Primary Use |
Configuration Management |
Configuration Management |
Configuration Management |
Infrastructure Provisioning |
| Language (Core) |
Python |
Ruby |
Ruby |
Go |
| Config Language |
YAML / Jinja2 |
Proprietary |
Ruby-based DSL |
HCL (DSL) |
| Agent Status |
Agentless |
Agent-based (or proxy) |
Agent-based |
Agentless |
| Model |
Push (via SSH) |
Pull |
Pull |
Push (via APIs) |
| Key Port |
TCP 22 (SSH) |
TCP 8140 |
TCP 10002 |
API Ports (varies) |
| Infrastructure |
Mutable |
Mutable |
Mutable |
Immutable |
| Approach |
Procedural (mostly) |
Declarative |
Procedural |
Declarative |
| Key Terminology |
Playbook, Inventory |
Manifest, Puppet Master |
Cookbook, Recipe, Run-list |
Provider, State File, Plan/Apply |
Things to note:
- While Ansible has some declarative elements, Red Hat officially categorizes it as procedural for exam purposes.
- Terraform and Ansible are frequently used together: Terraform provisions the infrastructure (immutable), and Ansible manages the ongoing configuration (mutable).
Key Terms, Ports, and Syntax Summary
- TCP 8140: Default port for Puppet agents to communicate with the Puppet Master.
- TCP 10002: Default port for Chef server to send configurations to clients.
- SSH (TCP 22): Protocol used by Ansible (and Puppet proxy agents) to connect to agentless devices.
- YAML: Data serialization language used by Ansible for Playbooks, Inventory, and Variables.
- Jinja2: Templating language used by Ansible.
- HCL (HashiCorp Configuration Language): Domain-Specific Language (DSL) used for Terraform configuration files.
- DSL (Domain-Specific Language): A computer language specialized to a particular application domain (e.g., HCL for Terraform, Ruby-based DSL for Chef).
- IaC: Infrastructure as Code.
# Conceptual Terraform Workflow Commands
terraform init # Initialize working directory and download providers
terraform plan # Preview the execution plan (Write -> Plan)
terraform apply # Execute the plan to reach the desired state (Apply)
terraform destroy # Tear down the provisioned infrastructure
! Conceptual Ansible/Jinja2 Template Snippet
hostname {{ hostname_var }}
interface GigabitEthernet0/1
ip address {{ ip_address_var }} {{ subnet_mask_var }}
no shutdown