MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Chef Command-Line Reference: Essential chef-solo, chef-client, and Knife Workflows

Originally published on 2015-09-20; fully revised and updated.

This page is a practical Chef CLI quick reference for DevOps engineers who need common commands in one place. It covers local recipe execution, cookbook generation, cookbook distribution, node bootstrap, and routine Knife operations, with notes where version differences can affect syntax.

Chef command families at a glance

Tool/command familyPrimary purposeTypical use case
chef-soloRun a recipe without Chef ServerLocal or standalone execution from a solo.rb config
chef-applyApply a single recipe file directlyQuick local tests on one machine
chef-client –local-modeConverge locally using a run listTest cookbook behavior without full server workflow
knife cookbook *Create/download/upload cookbooksManage cookbook lifecycle between local repo and server
knife bootstrapRegister and provision a nodeInitial onboarding of a target machine
knife node *Inspect and edit node metadata/run listsOperational node management
knife sshRun remote commands on selected nodesTrigger chef-client runs across nodes

Generate cookbook structure and files

Use these commands to scaffold a new cookbook and add template files. The examples below preserve the command intent from the original post.

chef generate cookbook learn_chef_httpd
knife cookbook create smartmontools -r md
chef generate template learn_chef_httpd index.htmlCode language: CSS (css)

Run recipes and cookbooks locally

These commands are commonly used during development and troubleshooting before deploying to managed nodes.

chef-solo -c /opt/chef/repo/config/solo.rb -o 'my_cookbook::recipe'
chef-apply hello.rb
sudo chef-client --local-mode --runlist 'recipe[learn_chef_httpd]'Code language: JavaScript (javascript)

Download and upload cookbooks

Use Knife cookbook commands to fetch cookbook artifacts and publish local cookbooks to Chef Server.

knife cookbook site download learn_chef_httpd
knife cookbook site install learn_chef_httpd
knife cookbook upload learn_chef_httpd
knife cookbook upload -a

Bootstrap nodes and manage run lists with Knife

The following examples show common node onboarding and day-2 operations. Replace hostnames, usernames, and credentials with your environment values.

knife bootstrap ADDRESS --ssh-user USER --ssh-password 'PASSWORD' --sudo --use-sudo-password --node-name node1 --run-list 'recipe[learn_chef_apache2]'
knife bootstrap uvo1t75faaktzc532w6.vm.cld.sr -x root -P Br356YS0iy --sudo --node-name firefox
knife bootstrap 123.45.6.789 -x username -P password --sudoCode language: JavaScript (javascript)
knife node list
knife node show node1
knife node edit name_of_node
knife node run_list add C2445575914.domain 'recipe[hptrain]'
knife node run_list set test-node 'recipe[iptables]'Code language: PHP (php)
knife ssh ADDRESS 'sudo chef-client' --manual-list --ssh-user USER --ssh-password 'PASSWORD'
ssh username@ipaddress -i mycredentials.pem sudo chef-clientCode language: PHP (php)

Typical Chef workflow

flowchart LR
    A[Generate cookbook] --> B[Add recipe and template]
    B --> C[Run local converge]
    C --> D[Download dependencies]
    D --> E[Upload cookbook]
    E --> F[Bootstrap node]
    F --> G[Run chef-client on node]
    G --> H[Validate node state]

Reference link preserved from the original post

The original page included a YouTube API-key troubleshooting reference: https://www.youtube.com/watch?v=ZCfrNvu6nMc.

Best practices and common pitfalls

  • Prefer SSH keys over plaintext passwords in bootstrap and remote execution commands.
  • Run local convergence first (chef-apply, chef-solo, or local-mode) before server upload.
  • Keep run lists explicit and review node state after every run-list change.
  • Validate command flags against your installed Chef Infra/Knife version, especially on older tutorials.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Chef Interview Q&A (Part 2): Resources, Run-Lists, Bootstrap, and Test Kitchen

A practical rewrite of classic Chef interview questions, focused on how Chef resources converge, how run-lists drive node configuration, and how to test cookbooks safely. Includes command examples, workflow diagrams, and comparison tables.

Read More

Chef Interview Questions, Explained: Resources, Run-Lists, Bootstrapping, and Test Kitchen

This updated guide converts classic Chef interview Q&A into a practical reference for real infrastructure work. It covers core concepts, execution order, bootstrap flow, key knife commands, and Test Kitchen testing patterns.

Read More

Chef Configuration Management Training: 3-Day Hands-On Curriculum for DevOps Teams

This revised guide turns a legacy Chef course post into a clear 3-day learning roadmap for DevOps teams. It covers the agenda, toolchain, workflow, and practical commands learners should expect.

Read More

Chef Training in Bangalore

DevOpsSchool introduce advance Chef Training in Bangalore with most experts professionals. Our Teams of Chef trainers offers chef online and classroom training from essential to advance level….

Read More

Chef Training Roadmap for DevOps Engineers: Course Tracks, Lab Workflow, and Practical Commands

This guide turns a promotional Chef training post into a practical roadmap for engineers. Compare course levels, understand the learning workflow, and use hands-on commands you can run in a lab.

Read More

Provision an AWS EC2 Instance with Chef (Legacy ChefDK Workflow)

A practical, step-by-step walkthrough for provisioning an AWS EC2 VM using the classic ChefDK and chef-provisioning approach. Includes workflow, commands, recipe examples, and validation checks for legacy environments.

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

Chef commands become much easier to use when you understand what each command changes on a node or server. Before running commands in production, test them in a safe environment and check the output for errors. It also helps to keep notes on common tasks, such as running recipes, managing cookbooks, and checking client status. Always verify the target environment before making changes. This habit can prevent small command mistakes from causing bigger configuration problems.

Sneha
Sneha
1 month ago

When using Chef commands across multiple environments, I find it important to distinguish between commands that only inspect configuration and those that can modify live infrastructure. A command that works on a development node may have very different consequences when executed against production systems. Keeping environment-specific configuration under version control, reviewing changes before applying them, and testing cookbook updates on a small group of nodes first can reduce unexpected configuration drift. It is also worth documenting version-specific command behavior so team members do not rely on outdated syntax during troubleshooting.

2
0
Would love your thoughts, please comment.x
()
x