Stage 4 · Provision
Ansible Fundamentals
Why Ansible
Agentless design, push vs pull, and where it fits next to Terraform.
Configuration Management
Configuration management is the practice of defining and maintaining system configurations consistently across environments. Instead of manually installing packages, editing files, and restarting services on each server, you describe the desired state declaratively and let a tool enforce it.
Ansible is an open-source automation engine that handles configuration management, application deployment, and orchestration. It uses YAML syntax to express desired state, making playbooks readable by anyone on the team — not just operations engineers.
Agentless Architecture
Unlike Puppet, Chef, or Salt, Ansible requires no agent on managed nodes. It connects over SSH (or WinRM for Windows), executes commands, and disconnects. This eliminates agent management overhead, version conflicts, and the need for a dedicated pull cycle.
# Ansible pushes tasks to managed nodes via SSH
# No daemon, no agent, no pull interval
# What happens on each run:
# 1. Control node connects via SSH
# 2. Generates and transfers a Python module
# 3. Executes the module on the remote host
# 4. Returns JSON output to the control node
# 5. Cleans up temporary filesBecause Ansible is agentless, you can start automating immediately — just install Ansible on one control node and provide SSH credentials to your fleet.
No agents to install, configure, or maintain. Your existing SSH infrastructure becomes your automation network. This dramatically lowers the barrier to entry compared to tools requiring agent deployment.
Push vs Pull Models
| Model | How It Works | Examples |
|---|---|---|
| Push | Control node pushes changes to hosts on demand | Ansible, Fabric |
| Pull | Agents periodically poll the server for changes | Puppet, Chef |
Push-based tools give you immediate visibility — when you run a playbook, you see results in real time. Pull-based tools offer eventual consistency but can make it harder to know exactly when changes were applied.
Ansible vs Terraform
Ansible and Terraform are often mentioned together but solve different problems. Terraform provisions infrastructure (VMs, networks, DNS records). Ansible configures what runs on that infrastructure (packages, configs, services).
# Terraform creates the VM
# terraform apply -> provisions EC2 instance
# Ansible configures what runs on it
- name: Configure web server
hosts: webservers
tasks:
- name: Install nginx
package:
name: nginx
state: present
- name: Start nginx
service:
name: nginx
state: started
enabled: yesUse Terraform for provisioning and Ansible for configuration. They complement each other — not compete.
Many teams use Terraform to provision infrastructure and then hand off to Ansible for configuration. Terraform's local-exec provisioner or a dynamic inventory plugin can trigger Ansible playbooks automatically.
Primary Use Cases
- Server provisioning — install packages, create users, configure services
- Application deployment — push code, manage dependencies, restart services
- Compliance enforcement — audit system state, apply CIS benchmarks
- Orchestration — coordinate multi-tier deployments across hundreds of servers
- Cloud automation — manage AWS, Azure, GCP resources alongside on-premises
Begin with a single playbook that configures one service. Once you see idempotency in action — running it twice produces the same result — you'll naturally expand to multi-server orchestration.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.