Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Chef: Infrastructure Automation Guide

By Kokil Thapa | Last reviewed: September 2026

Your servers drift the moment someone SSHs in and edits a config by hand. Chef: Infrastructure Automation Guide material exists because that drift breaks deployments, audits, and incident response. Chef Infra turns server state into versioned Ruby cookbooks that a client applies on a schedule. If you already use Terraform for infrastructure as code, Chef handles what Terraform leaves on the box: packages, users, services, and application runtime settings. This guide walks through a practical Chef workflow you can run on Ubuntu 22/24 hosts that serve PHP, Laravel, and WordPress stacks.

What is Chef and how does infrastructure automation with Chef work?

Chef is a configuration management platform built around resources, recipes, and cookbooks. You declare what a node should look like; the Chef Infra Client reads that code and brings the machine into compliance. The model is declarative at the recipe level and imperative at the resource level, which gives you fine control without shell-script spaghetti.

At runtime, Ohai collects node attributes—hostname, platform, memory, network interfaces—and merges them with cookbook defaults and role overrides. The client builds a resource collection, compares current state to desired state, and runs only the actions needed. That idempotent loop is the same principle covered in idempotent infrastructure principles, and it is why Chef fits long-lived VPS and bare-metal fleets.

Chef Infrastructure Automation OverviewChef Workstationknife, cookbooksChef ServerAPI + node dataManaged NodesInfra Client runsConvergence Loop on Each NodeOhai facts → compile recipes → update only driftReport back to Automate or plain logs
Chef infrastructure automation flow from workstation authoring to node convergence

Three deployment shapes matter in 2026:

  • Chef Infra Server — central API, node objects, environment pins, and role assignments. Best for teams above a handful of nodes.
  • chef-zero / local mode — no server; the client reads cookbooks from disk. Fine for learning and small fleets.
  • Policyfiles — modern workflow that locks cookbook versions into a single policy archive. Prefer this over legacy Berkshelf + environments when starting fresh.

Chef does not replace your entire stack. Pair it with Terraform for cloud objects, Packer for golden images, and GitLab CI for pipeline gates. On sister sites I maintain with Deployer 7, Chef-style discipline—everything in Git, nothing manual on prod—mirrors what build pipeline automation best practices preach, even when the actual config tool is Ansible or shell plus CI.

How do you install Chef Workstation and bootstrap your first node?

Start on a Linux or macOS admin machine. Install Chef Workstation, which bundles chef, knife, Cookstyle, Test Kitchen, and InSpec. Official packages live on the Progress Chef download site; verify checksums before install.

Install Chef Workstation on Ubuntu

wget https://packages.chef.io/files/stable/chef-workstation/latest/ubuntu/24.04/chef-workstation_amd64.deb
sudo dpkg -i chef-workstation_amd64.deb
chef -v
knife -v

Create a cookbook repo skeleton:

chef generate repo infra-chef
cd infra-chef
chef generate cookbook cookbooks/base_server
chef generate cookbook cookbooks/laravel_app

Bootstrap a node with knife

Bootstrapping installs the Chef Infra Client and registers the node against your Chef Server. Replace placeholders with your values.

knife bootstrap 203.0.113.10 \
  -x deploy \
  --sudo \
  --node-name web01.prod \
  --run-list 'recipe[base_server]' \
  --ssh-verify-host-key never

For policyfile-first workflows, export a locked policy and apply it during bootstrap:

cd cookbooks/base_server
chef install
chef export base-prod --archive-policyfile
knife bootstrap 203.0.113.10 -x deploy --sudo \
  --policy-name base-prod \
  --policy-group production

On a real client project hosting Laravel 12 on Ubuntu 24.04, I treat bootstrap like a contract. The node must land with PHP 8.3 FPM, Redis, UFW rules, and log rotation before Deployer ever runs. That ordering prevents the classic “app deploy succeeded but PHP extension missing” failure mode described in Linux system administration support work.

How do you write Chef cookbooks and recipes for production servers?

A cookbook is a reusable unit. A recipe is a Ruby file listing resources. A resource maps to a concrete system item—package, service, template, user, and hundreds more.

Example: base PHP-FPM recipe for Laravel

This recipe installs PHP 8.3, enables FPM, and templates a pool file. Adjust version pins to match your app; Laravel 13 needs PHP 8.3 or higher.

# cookbooks/laravel_app/recipes/php_fpm.rb
package 'php8.3-fpm' do
  action :install
end

template '/etc/php/8.3/fpm/pool.d/app.conf' do
  source 'app.conf.erb'
  owner 'root'
  group 'root'
  mode '0644'
  variables(
    app_user: node['laravel']['user'],
    memory_limit: node['laravel']['memory_limit']
  )
  notifies :restart, 'service[php8.3-fpm]', :delayed
end

service 'php8.3-fpm' do
  action [:enable, :start]
end

Pair it with attributes in attributes/default.rb:

default['laravel']['user'] = 'deploy'
default['laravel']['memory_limit'] = '256M'
default['laravel']['docroot'] = '/var/www/app/current/public'

Use a role or policy group to compose recipes:

# roles/web.json (legacy) — prefer Policyfile run lists
{
  "name": "web",
  "run_list": [
    "recipe[base_server::firewall]",
    "recipe[base_server::users]",
    "recipe[laravel_app::php_fpm]",
    "recipe[laravel_app::nginx_site]"
  ]
}
Chef Cookbook Anatomycookbooks/laravel_apprecipes/php_fpm.rbtemplates/app.conf.erbattributes/default.rbtest/InSpec + KitchenCustom resources wrap repeated patternslaravel_site, mysql_app_db, certbot_vhost
Standard Chef cookbook folders for recipes, templates, attributes, and automated tests

Wrap repeated patterns in custom resources. If you configure ten similar vhosts across legal-tech portals, one resource beats ten copy-pasted recipe blocks. Keep secrets out of Git; load passwords from Chef Vault, HashiCorp Vault, or cloud secret stores via node data bags populated at bootstrap.

Validate JSON policy files and attribute hashes early. A quick pass through a JSON formatter and validator catches trailing commas before CI wastes ten minutes on a Kitchen run.

Chef vs Ansible vs Puppet: which configuration tool fits your team?

Teams often pick Chef when they want Ruby-native extensibility, strong enterprise support, and a mature compliance story with InSpec. Ansible wins on agentless SSH simplicity. Puppet excels at large declarative catalogs with strict ordering.

CriteriaChef InfraAnsiblePuppet
Agent on nodeYes — Infra Client daemon or cronNo — SSH pushYes — Puppet Agent
LanguageRuby recipes and resourcesYAML playbooks + JinjaPuppet DSL
Learning curveSteeper — Ruby helpsGentlest for adminsModerate — DSL concepts
Compliance testingInSpec (first-class)Ansible Lint, MoleculeInspec or Puppet Litmus
Ideal fleet sizeTens to thousandsSmall to largeLarge enterprise
Drift correctionContinuous convergenceOn-demand runsContinuous convergence

Read the fuller breakdown in Ansible vs Puppet vs Chef vs Salt. My default for a five-node Laravel fleet in Nepal is still often Ansible or plain GitLab CI plus Deployer, because the team can read YAML on day one. Chef earns its place when compliance audits, heterogeneous OS mixes, or policy-driven rollouts justify the agent footprint and Ruby skill investment.

Push vs Pull Configuration ModelsAnsible PushAdmin runs playbook over SSHChange happens once per invokeChef PullClient pulls policy on scheduleDrift self-heals automaticallyChoose pull when nodes must stay compliantChoose push when you want zero agent and fast ad-hoc fixesHybrid teams use Terraform plus either model
Chef pull-based convergence compared with Ansible push-based playbooks

How do you test Chef cookbooks before touching production?

Untested cookbooks are production incidents waiting for a maintenance window. Use Test Kitchen to spin up ephemeral VMs or containers, apply your cookbook, and verify with InSpec assertions.

Test Kitchen workflow

  1. Define a Kitchen.yml driver — Docker for speed, Vagrant or cloud for fidelity.
  2. Point the suite at your cookbook and run list.
  3. Run kitchen converge to apply recipes.
  4. Run kitchen verify to execute InSpec profiles.
  5. Destroy the instance or integrate the job into GitLab CI.
# Kitchen.yml excerpt
---
driver:
  name: dokken
  chef_version: 18

provisioner:
  name: chef_infra
  product_name: chef
  install_strategy: always

platforms:
  - name: ubuntu-24.04

suites:
  - name: default
    run_list:
      - recipe[laravel_app::php_fpm]
    verifier:
      name: inspec
# test/integration/default/default_test.rb
describe package('php8.3-fpm') do
  it { should be_installed }
end

describe service('php8.3-fpm') do
  it { should be_enabled }
  it { should be_running }
end

Run Cookstyle locally and in CI to enforce Ruby style:

cookstyle cookbooks/
kitchen test

This mirrors the testing mindset in testing infrastructure code with Terratest, but for OS-level resources instead of cloud APIs. Wire Kitchen into the same pipeline that runs build automation jobs so cookbook merges cannot skip verification.

External references worth bookmarking: the official Chef documentation for resource syntax, and the Chef Infra Client repository when you need to understand client behaviour at the source level.

How do you operate Chef safely in production web stacks?

Production Chef is less about writing recipes and more about change control. Pin cookbook versions, segregate environments, and treat the Chef Server API like production infrastructure.

Operational checklist

  • Run the client every 15–30 minutes via systemd timer or cron, not only on deploy day.
  • Upload cookbooks through CI after Kitchen passes; block manual knife cookbook upload on prod.
  • Separate staging and production policy groups; promote by bumping the policy revision, not editing live nodes.
  • Log to Chef Automate or ship JSON reports to your SIEM if compliance requires it.
  • Keep handler cookbooks for Slack or email alerts when convergence fails twice in a row.
Production Chef Delivery PipelineGit PushCI Kitchen+ CookstyleUploadPolicy archiveStagingconvergePromote to production policy groupNodes pull on next interval — no SSH requiredRollback = redeploy previous policy revision
Git-driven Chef infrastructure automation pipeline with staging gate before production convergence

Chef complements application deploy tools. Deployer swaps Laravel releases; Chef keeps PHP-FPM pools, opcache settings, and system users stable underneath. That split appears across projects like Adventure Third Pole Trek and the notary sister sites on shared EC2, where Laravel Envoy handles app tasks while baseline OS config stays scripted.

For immutable layers, bake a Packer image with baseline hardening, then let Chef finish node-specific tuning. See immutable infrastructure with Packer for the image half of that pattern. If you are Kubernetes-heavy, platform teams sometimes prefer Crossplane for cloud APIs while Chef still configures worker AMIs.

Cost reality for Nepal SMBs: a managed Chef Server or Automate licence can exceed Rs 15,000/month (~USD 110) before cloud fees. Chef Solo and policyfile archives on object storage reduce that to software labour only. Price the Ruby maintenance hours honestly when comparing against Ansible, which many agencies already know from Ansible roles work.

When convergence breaks after a PHP upgrade, check Ohai output first, then run chef-client -l info once manually. Nine times out of ten the failure is a template variable missing after you renamed a node attribute. Document attribute contracts the same way you document API payloads on API development engagements.

Security basics still apply. Restrict sudo on bootstrap users, rotate validator keys, and firewall the Chef Server API to admin IPs. Pair automated config with vulnerability management automation so package resources bump OpenSSL and curl without waiting for a quarterly ticket.

Need a human review of your fleet? Support and maintenance covers the same Ubuntu, MySQL 8.4, and PHP-FPM stacks Chef manages. For greenfield platforms, enterprise application development includes IaC choices during architecture, not after launch.

Key Takeaways

  • Model servers as cookbooks under Git; never treat SSH edits as the source of truth.
  • Prefer Policyfiles over legacy environment pins when starting a new Chef repo in 2026.
  • Run Test Kitchen and InSpec on every merge before any cookbook touches staging nodes.
  • Use Chef for continuous drift correction; pair it with Terraform for cloud provisioning.
  • Compare agent overhead against Ansible push runs—small teams may trade Ruby power for YAML speed.
  • Promote policy revisions through staging groups, and roll back by redeploying the last known-good archive.

People Also Ask

Is Chef still maintained and relevant in 2026?

Yes. Progress Software maintains Chef Infra, Workstation, and InSpec. Enterprise fleets still rely on pull-based convergence and compliance profiles. Community cookbooks on the Supermarket remain active, though many greenfield teams also evaluate Ansible or cloud-native tooling.

Do I need a Chef Server for a small VPS fleet?

Not necessarily. Policyfile archives stored in S3-compatible object storage plus periodic chef-client runs can serve five to twenty nodes. Add a Chef Server when you need granular ACLs, search indexes across nodes, and central reporting at scale.

Can Chef manage Windows and Linux in the same org?

Chef Infra supports both platforms with separate cookbooks and Ohai plugins. Mixed fleets were Chef’s historical strength. Verify each resource exists on the target OS, and split cookbooks rather than branching every recipe with heavy if platform? logic.

How does Chef relate to GitOps?

GitOps usually means declarative Kubernetes manifests reconciled by a controller. Chef applies the same reconcile idea to VMs and bare metal. Read GitOps for infrastructure vs application to decide where Chef fits beside Argo CD or Flux.

Ship repeatable servers, not one-off fixes

A solid Chef: Infrastructure Automation Guide workflow turns your baseline Ubuntu image into a tested, promotable policy archive. Start with one cookbook—PHP-FPM, Nginx, UFW—and prove convergence in Kitchen before you bootstrap production. Layer in compliance scans, CI uploads, and staging groups as the fleet grows. If you want help mapping Chef, Ansible, or Deployer into one pipeline for a Laravel or legal-tech platform, contact us or browse the Notary Kathmandu deployment story for a real multi-site example. More background lives on the about page and in zero-downtime infrastructure updates for the Terraform side of the same problem.

Frequently Asked Questions

Chef describes desired server state in versioned Ruby cookbooks and recipes. Chef Infra Client applies them on a schedule so each node converges idempotently to match Git, not manual SSH edits.

Ohai collects node attributes such as hostname, platform, and memory, then merges them with cookbook defaults and role or policy overrides. The client builds a resource collection, compares current state to desired state, and runs only the actions needed. That pull-based, idempotent loop suits long-lived VPS and bare-metal fleets where drift from hand-edited configs breaks deployments and audits.

Download the current amd64 deb from packages.chef.io, verify the checksum, then install with dpkg. Chef Workstation bundles chef, knife, Cookstyle, Test Kitchen, and InSpec. Confirm with chef -v and knife -v, then run chef generate repo to scaffold your cookbook repository before authoring your first cookbook.

Not always. Policyfile archives on S3-compatible object storage plus periodic chef-client runs can serve five to twenty nodes without a central server.

Chef Infra Server provides a central API, node objects, environment pins, and role assignments for teams above a handful of nodes. Chef-zero or local mode reads cookbooks from disk with no server, which suits learning and tiny fleets. Policyfiles lock cookbook versions into a single policy archive and are the preferred 2026 workflow over legacy Berkshelf plus environment pins when starting fresh.

From your workstation, run knife bootstrap against the target IP with your SSH user, sudo, a node name, and either a run list or a policy name and policy group. Bootstrapping installs Chef Infra Client and registers the node. On Laravel stacks, treat bootstrap as a contract: PHP 8.3 FPM, Redis, UFW rules, and log rotation must exist before Deployer runs, preventing app deploys that succeed while system packages are missing.

A cookbook is reusable; a recipe is a Ruby file listing resources such as package, service, and template. Pin PHP 8.3 FPM packages, template pool files with node attributes for app user and memory_limit, and notify service restarts. Compose recipes through roles or, preferably, Policyfile run lists covering firewall, users, PHP-FPM, and Nginx. Wrap repeated vhost patterns in custom resources and keep secrets out of Git using Chef Vault or external secret stores.

Chef fits teams wanting Ruby-native extensibility, enterprise support, and first-class InSpec compliance testing, with continuous agent-based drift correction. Ansible wins on agentless SSH simplicity and YAML readability for admins. Puppet suits large declarative catalogs with strict ordering. For a five-node Laravel fleet in Nepal, many teams still pick Ansible or GitLab CI plus Deployer because YAML is easier on day one; Chef earns its place when compliance audits or policy-driven rollouts justify the agent and Ruby investment.

Use Test Kitchen to spin ephemeral VMs or containers, converge your cookbook, then verify with InSpec assertions. Define a Kitchen.yml driver such as dokken for Docker speed, set your run list, run kitchen converge and kitchen verify, and run Cookstyle locally and in CI. Wire kitchen test into the same GitLab CI pipeline that gates application builds so cookbook merges cannot skip verification. Untested cookbooks are production incidents waiting for a maintenance window.

A managed Chef Server or Automate licence can exceed Rs 15,000 per month (~USD 110) before cloud fees. Policyfile archives on object storage with Chef Solo-style runs reduce that to software labour only.

Run chef-client every 15 to 30 minutes via systemd timer or cron, not only on deploy day. Upload cookbooks through CI after Kitchen passes and block manual knife cookbook upload on production. Separate staging and production policy groups and promote by bumping the policy revision. Log to Chef Automate or ship JSON reports to a SIEM if compliance requires it. Add handler cookbooks for alerts when convergence fails twice. Chef keeps PHP-FPM pools and system users stable while Deployer swaps Laravel releases.

Chef does not replace your entire stack. Terraform provisions cloud objects; Packer bakes golden images with baseline hardening; GitLab CI gates cookbook uploads and application deploys. Chef handles what Terraform leaves on the box: packages, users, services, and runtime settings. That split mirrors build pipeline automation best practices: everything in Git, nothing manual on production, even when sister sites use Deployer 7 for Laravel app releases on shared EC2 infrastructure.

Check Ohai output first, then run chef-client -l info once manually on the node. Nine times out of ten the failure is a template variable missing after you renamed a node attribute. Document attribute contracts the same way you document API payloads so recipe authors know which keys recipes expect. Validate JSON policy files and attribute hashes early in CI to catch trailing commas before a Kitchen run wastes ten minutes.

Restrict sudo on bootstrap users, rotate validator keys regularly, and firewall the Chef Server API to admin IPs only. Keep secrets out of Git and load passwords from Chef Vault, HashiCorp Vault, or cloud secret stores. Pair automated package resources with vulnerability management so OpenSSL and curl updates ship without waiting for a quarterly ticket. Treat the Chef Server API itself as production infrastructure requiring the same change control as your web tier.

Yes. Progress Software maintains Chef Infra, Workstation, and InSpec, and enterprise fleets still rely on pull-based convergence and compliance profiles. Community cookbooks on the Supermarket remain active, though many greenfield teams also evaluate Ansible or cloud-native tooling. Chef supports Windows and Linux in mixed fleets, and the reconcile model parallels GitOps for VMs and bare metal even when Kubernetes teams use Argo CD or Flux for cluster manifests instead.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: