← Back to DevOps
© 2025 sampathirao yoganandh
Week 9 – 12 · CO-4

Configuration Management

Chef, Puppet, Ansible, SaltStack — Infrastructure as Code  CO-4

Chef (Week 9)

Chef is a Configuration Management and Infrastructure as Code (IaC) tool used to automate the installation and configuration of software on servers using code. Instead of manually installing software on each server, you write code called recipes and Chef installs automatically.

Why Chef?

Without ChefWith Chef
Login to each server manuallyWrite one recipe — Chef installs on all servers
Time consuming & error-proneAutomated, consistent, scalable
Hard to replicate environmentsIdempotent — same result every run

Chef Architecture

Model 1: Chef Server Model (Enterprise)

ComponentRole
Chef ServerStores all configuration (cookbooks)
Chef WorkstationWhere cookbooks are written and uploaded
Chef ClientRuns on each managed node
NodeManaged server (EC2 instance)
Flow — Pull Model Workstation → Upload cookbook → Chef Server  |  Node → Pull configuration → Apply

Model 2: Chef Solo / Local Mode

Simpler version with no Chef Server. Recipes stored locally and run using chef-client --local-mode. Best for learning, small projects, or 2–5 servers.

Chef Terminology

TermDescription
CookbookCollection of recipes (e.g., nginx_cookbook, java_cookbook)
RecipeInstructions written in Ruby DSL
ResourceBasic unit — package, service, file
NodeAny managed server (EC2 instance)
Run ListOrdered list of recipes to run on a node

Sample Recipe (Ruby DSL)

package 'nginx' do
  action :install
end

service 'nginx' do
  action [:enable, :start]
end

Chef Step-by-Step Procedure

Step 1: Install Chef Workstation

wget https://packages.chef.io/files/stable/chef-workstation/...
sudo dpkg -i chef-workstation_*.deb
chef --version

Step 2: Create Cookbook

chef generate cookbook java_cookbook
# Creates structure:
# java_cookbook/
#   recipes/default.rb
#   metadata.rb

Step 3: Write Recipe

# java_cookbook/recipes/default.rb
package 'openjdk-17-jdk' do
  action :install
end

Step 4: Transfer Cookbook to Node

scp -r java_cookbook ubuntu@<node-ip>:/home/ubuntu/

Step 5: Fix Directory Structure on Node

mkdir ~/cookbooks
mv java_cookbook cookbooks/
# Chef local-mode expects: ~/cookbooks/java_cookbook/

Step 6: Run Chef in Local Mode

sudo chef-client --local-mode -o recipe[java_cookbook]
# Nginx node:
sudo chef-client --local-mode --runlist 'recipe[nginx_cookbook]'

Puppet (Week 10)

Puppet is a Configuration Management and Infrastructure as Code (IaC) tool that manages servers automatically using code instead of manual configuration.

Puppet Architecture — Pull Model

ComponentRole
Puppet MasterCentral configuration server
Puppet AgentInstalled on each managed node
NodeManaged server (EC2 instance)
ManifestConfiguration file (.pp file — Puppet DSL)
CatalogCompiled configuration sent from Master to Agent
Puppet Workflow Agent runs on node → Agent contacts Master → Master sends catalog → Agent applies configuration → Agent reports back (every 30 minutes by default)

Puppet Terminology

Manifest (.pp file)

package { 'nginx':
  ensure => installed,
}

service { 'nginx':
  ensure => running,
  enable => true,
}

Node-specific Configuration

node 'ec2-nginx' {
  package { 'nginx': ensure => installed }
  service { 'nginx': ensure => running }
}

node default {
  package { 'openjdk-17-jdk': ensure => installed }
}
Idempotency — Key Concept If you run Puppet 100 times, it will not reinstall packages that are already installed. It only makes changes when the actual state differs from the desired state. This is called idempotent behavior.

Puppet Step-by-Step Procedure

Step 1–2: Install Puppet Master & Agents

# On Master (EC2-1):
sudo apt install puppetserver -y
sudo systemctl start puppetserver

# On Nodes (EC2-2, EC2-3):
sudo apt install puppet-agent -y

Step 3: Configure Agent to Point to Master

# On each node — edit puppet.conf:
[main]
server = <master-hostname>

Step 4: Sign Certificates on Master

# On Master — list pending requests:
sudo puppetserver ca list

# Sign all agents:
sudo puppetserver ca sign --all

Step 5: Run Puppet Agent on Nodes

sudo puppet agent -t
# Output: Notice: Applied catalogue in X seconds

Ansible (Week 11)

Ansible (by Red Hat) is an agentless automation and configuration management tool used to install software, configure servers, deploy applications, and manage cloud infrastructure. It uses SSH — no agent installation needed on target nodes.

Why Ansible?

Without AnsibleWith Ansible
Login to 20 EC2 servers one by oneRun one playbook — configures all servers
Manual, error-proneAutomated, repeatable, idempotent
No agent neededUses SSH — agentless architecture

Ansible Architecture — Push Model

ComponentRole
Control NodeWhere Ansible is installed
Managed NodesTarget servers (EC2 instances)
InventoryFile listing target servers
PlaybookYAML configuration file with tasks
ModuleSmall task unit (apt, service, copy, file, etc.)

Ansible Concepts

Inventory File

[java_servers]
192.168.1.10

[nginx_servers]
192.168.1.20

Playbook (YAML)

- name: Install Java on all java servers
  hosts: java_servers
  become: yes
  tasks:
    - name: Install OpenJDK 17
      apt:
        name: openjdk-17-jdk
        state: present

    - name: Start Java verification
      command: java -version

Key Ansible Commands

# Run a playbook:
ansible-playbook setup.yml

# Test connectivity:
ansible all -m ping

# Run ad-hoc command on all hosts:
ansible all -m shell -a "java -version"
Important Features Agentless (SSH only) · Simple YAML syntax · Idempotent · Fast setup · No master server required

SaltStack (Week 12)

SaltStack is a fast configuration management and remote execution tool that manages large-scale infrastructure using a Master–Minion architecture. It supports both push and pull models and uses ZeroMQ for very fast communication.

Salt Architecture

ComponentRole
Salt MasterCentral control server
Salt MinionInstalled on each managed node
State File (.sls)YAML configuration file
PillarSecure variable data (passwords, keys)
GrainsSystem information (OS, IP, memory)

Push Model (Remote Execution)

# Master pushes command to all minions instantly:
salt '*' test.ping
salt '*' cmd.run 'apt update'

Pull Model (State Application)

# Minions apply states from master:
salt '*' state.apply

Salt State File

# install_java.sls
install_java:
  pkg.installed:
    - name: openjdk-17-jdk

start_java_check:
  cmd.run:
    - name: java -version

SaltStack Setup

# Install Master (EC2-1):
sudo apt install salt-master -y

# Install Minion (EC2-2, EC2-3):
sudo apt install salt-minion -y

# Configure minion to point to master:
# Edit /etc/salt/minion → master: <master-ip>

# Accept minion keys on master:
salt-key -L        # List pending
salt-key -A        # Accept all

# Test:
salt '*' test.ping

Tool Comparison

FeatureChefPuppetAnsibleSaltStack
LanguageRuby DSLPuppet DSLYAMLYAML
ModelPullPullPushPush & Pull
Agent requiredYes (Chef Client)Yes (Puppet Agent)No (SSH)Yes (Salt Minion)
Config fileRecipe (.rb)Manifest (.pp)Playbook (.yml)State File (.sls)
SpeedModerateModerateModerateVery Fast (ZeroMQ)
Learning curveHigh (Ruby)MediumLow (YAML)Medium
Best forComplex IaCLarge enterpriseSimple automationLarge-scale / fast
📄

Configuration Management — Notes PDF

Week 9–12 · Chef, Puppet, Ansible & SaltStack

⬇ Download PDF