In the fast-paced world of IT infrastructure and DevOps, automation is key to managing systems efficiently. Chef has emerged as one of the most powerful automation and configuration management tools, allowing you to treat your infrastructure as code.
In this hands-on guide, I will walk you through how to get started with Chef on Ubuntu 18.04 from the ground up. By the end, you’ll have the foundation to start automating infrastructure deployments, configurations, and application management using Chef‘s incredible capabilities.
So buckle up, fellow techie! We have an exciting journey ahead.
Why Chef?
Before we dive into the installation, you may be wondering – why use Chef in the first place? What makes it so useful for automation tasks?
Here are some key reasons Chef is a top choice for infrastructure management:
-
Infrastructure as Code – Chef allows you to define infrastructure configurations, environments, and policy rules as code using the powerful Ruby DSL. This makes them repeatable, portable, and testable.
-
Powerful Abstractions – Chef introduces useful abstractions like cookbooks, recipes, resources, and providers. This allows for modular, reusable code components.
-
Ideal for the Cloud – Chef is perfect for managing dynamic cloud infrastructure. Integrations with AWS, GCP, Azure, and more allow full infrastructure automation.
-
Robust Community – Chef benefits from a thriving open-source community with over 1,300 cookbooks and plugins available. The ecosystem is always growing.
According to a Flexera 2022 report, Chef usage grew from 49% to 55% among respondents, indicating strong adoption. With Chef skills in high demand, it‘s a great time to add Chef to your automation toolbox.
Now let‘s move on to installing Chef on Ubuntu.
Chef Architecture Overview
Before we install Chef, it‘s important to understand the architecture and components involved:

Overview of Chef architecture (image: RealPython)
-
Chef Workstation – The primary location where users interact with Chef tools. You author cookbooks here and use Knife for configuration tasks. We will install the Chef Workstation package on an Ubuntu machine.
-
Chef Server – Acts as the hub for all configuration data. The Chef Server stores cookbooks, policies, metadata, etc. Nodes check in with the server to pull latest configurations.
-
Chef Nodes – The servers and devices managed by Chef. Chef clients are installed on each node to apply Chef configurations from the server.
-
Chef Client – The agent that runs on each node and applies configurations from the Chef Server. It registers new nodes and performs convergence.
-
Chef Repo – A repository structure for managing Chef cookbooks source code. The repo contains cookbooks, data bags, roles, and more.
This separation of concerns provides powerful abstraction and flexibility in managing infrastructure at scale.
With the basics covered, let‘s get Chef installed.
Installation Prerequisites
For this tutorial, I will use 3 fresh Ubuntu 18.04 servers to simulate a real Chef setup:
Chef Server
- Hostname: chef-server
- IP: 172.20.1.10
Workstation
- Hostname: workstation
- IP: 172.20.1.11
Node
- Hostname: node
- IP: 172.20.1.12
You can use any servers, VMs, or cloud instances to follow along.
Here are the prerequisites before installation:
- Latest patched Ubuntu 18.04 servers (any similar OS works too)
- Root access on all servers
- OpenSSH server installed on all servers
- Passwordless SSH configured between servers (key-based authentication)
- Hostname resolution between servers via DNS or hostfile edits
Start by updating all packages:
# Run on ALL servers
sudo apt update
sudo apt upgrade -y
Let‘s now install the Chef Server, the central repository of our infrastructure data.
Installing and Configuring Chef Server
The Chef Server acts as the backbone for our Chef setup where all configuration data will live. It maintains state and syncs configurations to nodes.
Follow these steps to install Chef Server on Ubuntu 18.04:
-
Install dependencies:
sudo apt install -y curl git -
Download and install the Chef Server package:
# Download latest package curl -LO https://packages.chef.io/files/stable/chef-server/14.3.37/ubuntu/18.04/chef-server-core_14.3.37-1_amd64.deb # Install Chef Server sudo dpkg -i chef-server-core_*.deb -
Reconfigure the Chef Server. This initializes certificates, keys, and data structures:
sudo chef-server-ctl reconfigureOn completion, you should see output like:
Chef Infra Server Reconfigured! -
Start Chef Server services:
sudo chef-server-ctl start -
Check status to verify all services are running:
sudo chef-server-ctl status run: bookshelf: (pid 24452) 768s; run: log: (pid 2953) 951s run: nginx: (pid 2318) 772s; run: log: (pid 30216) 908s run: oc_bifrost: (pid 2563) 10s; run: log: (pid 12091) 300s
The core Chef Server is now ready. But we still need to create administrative credentials before it can be used.
Adding Chef Admin User and Organization
To start managing nodes and configurations, we need to create an admin user and organization on the Chef Server:
-
Create the admin user
chefadmin. Specify the username, full name, password and RSA private key path:sudo chef-server-ctl user-create chefadmin "Chef Admin" [email protected] ‘Passw0rd!‘ --filename /home/chefadmin/chefadmin.pem -
Verify the user was added:
sudo chef-server-ctl user-list -
Create an organization named
myorg. Specify full name and admin user:sudo chef-server-ctl org-create myorg "My Company Inc." --association_user chefadmin --filename /home/chefadmin/myorg-validator.pem -
Confirm organization creation:
sudo chef-server-ctl org-list
The PEM keys will be needed later when connecting the workstation.
With the core Chef Server fully configured, let‘s set up a Chef Workstation next.
Setting Up Chef Workstation
The Chef Workstation is where users will do the actual development – authoring cookbooks, managing data, and configuring Chef. It‘s our primary interface for interacting with Chef.
Follow these steps to configure a workstation:
-
Install Chef Workstation package on Ubuntu:
# Download curl -LO https://packages.chef.io/files/stable/chef-workstation/0.17.14/ubuntu/18.04/chef-workstation_0.17.14-1_amd64.deb # Install Chef Workstation sudo dpkg -i chef-workstation_*.deb -
Update RubyGems:
chef gem update --system -
Create a Chef Repo directory for our code:
mkdir -p ~/chef-repo cd ~/chef-repo -
Copy PEM keys from the Chef Server:
# Chef Admin Key scp chefadmin@chef-server:/home/chefadmin/chefadmin.pem .chef/ # Org Validator Key scp chefadmin@chef-server:/home/chefadmin/myorg-validator.pem .chef/ -
Create a .chef directory:
mkdir -p .chef -
Create a configuration file at
.chef/config.rbwith the following:current_dir = File.dirname(__FILE__) log_level :info log_location STDOUT node_name ‘chefadmin‘ client_key "#{current_dir}/chefadmin.pem" validation_client_name ‘myorg-validator‘ validation_key "#{current_dir}/myorg-validator.pem" chef_server_url ‘https://chef-server/organizations/myorg‘ cookbook_path ["#{current_dir}/../cookbooks"] -
Fetch SSL certificates:
knife ssl fetch
This completes the core workstation setup. We can now start using knife commands.
Bootstrapping Chef Nodes
The final step is to install the Chef client on nodes and have them connect to the Chef Server. This process is known as "bootstrapping".
Let‘s bootstrap our node:
-
Install Chef client:
# On Node curl -LO https://omnitruck.chef.io/install.sh && sudo bash ./install.sh -v 15 -
Bootstrap the node using knife from the workstation:
# On Workstation knife bootstrap 172.20.1.12 --ssh-user chefadmin --sudo --ssh-identity-file ~/chefadmin_rsa --node-name node1Enter the SSH password when prompted.
-
Check that the node is registered:
knife node list node1
The node will now pull down configurations from the Chef Server.
Managing Cookbooks and Recipes
Now that we have a fully configured Chef setup, we can start authoring cookbooks to automate infrastructure management.
Cookbooks contain recipes that specify how to configure resources and systems. They provide reusable, modular configurations.
Here is a quick example cookbook structure:
myapp/
attributes/
default.rb
recipes/
default.rb
templates/
default.conf.erb
files/
default.txt
metadata.rb
Let‘s create a new cookbook:
# On Workstation
chef generate cookbook myapp
cd myapp
Edit recipes in recipes/default.rb:
package ‘nginx‘
service ‘nginx‘ do
action [:enable, :start]
end
template ‘/etc/nginx/sites-available/default‘ do
source ‘default.conf.erb‘
variables(
server_name: ‘myapp.com‘
)
end
Add a template at templates/default.erb:
server {
listen 80;
server_name <%= @server_name %>;
# app config
}
Update metadata.rb with dependencies:
depends ‘nginx‘
Test the cookbook:
kitchen test
Upload it to the Chef Server:
knife upload cookbooks/myapp
Bootstrap a new node with the cookbook:
knife bootstrap node2 -r ‘recipe[myapp]‘
This was just a simple example to validate your Chef setup. Refer to the Chef docs for in-depth tutorials on cookbook authoring.
Closing Thoughts
In this comprehensive guide, we installed Chef Server, Chef Workstation, and bootstrapped a node on Ubuntu 18.04. With the foundation in place, you can now start using Chef to automate infrastructure, application deployments, and more.
Here are some additional best practices as you grow your Chef implementation:
-
Maintain cookbooks under version control with Git. Use Chef Supermarket for community cookbooks.
-
Leverage Test Kitchen for fast cookbook testing. Write ChefSpec unit tests.
-
Use roles, environments, and policyfiles to model infrastructure states.
-
Integrate Chef with CI/CD pipelines for continuous delivery.
-
Monitor your Chef fleet using Chef Automate. Track compliance and visibility.
-
Use Chef search capabilities to query infrastructure state in real-time.
I hope this guide served as a good starting point for your Chef journey. Infrastructure automation helps tame complexity and improves efficiency. Chef makes it possible to define infrastructure as code and manage it at scale.
Let me know if you have any other questions! I‘m always happy to help fellow techies master new tools. Next stop – infrastructure automation!