#Chef

Ruby-based configuration management.


#Overview

ComponentDescription
WorkstationWhere you write cookbooks
Chef ServerCentral configuration store
NodesManaged servers

#Cookbook Example

ruby
1# cookbooks/myapp/recipes/default.rb
2package 'nginx' do
3  action :install
4end
5
6service 'nginx' do
7  action [:enable, :start]
8end
9
10template '/etc/nginx/nginx.conf' do
11  source 'nginx.conf.erb'
12  variables(
13    port: node['myapp']['port']
14  )
15  notifies :reload, 'service[nginx]'
16end

#Commands

bash
1# Create cookbook
2chef generate cookbook myapp
3
4# Test locally
5kitchen test
6
7# Upload to server
8knife cookbook upload myapp
9
10# Apply to node
11knife ssh 'name:web*' 'sudo chef-client'

[!TIP] Pro Tip: Chef is powerful but has a steep learning curve. Consider Ansible for simpler needs!