#339 Chef Solo Basics pro
Chef is a provisioning tool which allows you to spin up production servers automatically. Here I show how to get started with Chef Solo and create a custom cookbook.
- Download:
- source codeProject Files in Zip (83.5 KB)
- mp4Full Size H.264 Video (46.4 MB)
- m4vSmaller H.264 Video (21.9 MB)
- webmFull Size VP8 Video (22.1 MB)
- ogvFull Size Theora Video (49.3 MB)
Resources
Chef Alternatives
terminal
ssh root@72.14.183.209 # on server curl -L https://gist.github.com/raw/2307959/ff2d251c9f4f149c5ca73c873ad8990711b3ca74/chef_solo_bootstrap.sh | bash ruby -v chef-solo -v mkdir /var/chef cd /var/chef mkdir -p cookbooks/main/recipes vim cookbooks/main/recipes/default.rb vim solo.rb chef-solo -c solo.rb vim node.json chef-solo -c solo.rb -j node.json exit # on local scp -r root@72.14.183.209:/var/chef . mate chef cd chef rsync -r . root@72.14.183.209:/var/chef ssh root@72.14.183.209 "chef-solo -c /var/chef/solo.rb" brew install ssh-copy-id ssh-copy-id root@72.14.183.209 openssl passwd -1 "theplaintextpassword" ssh deployer@72.14.183.209
chef/solo.rb
cookbook_path File.expand_path("../cookbooks", __FILE__) json_attribs File.expand_path("../node.json", __FILE__)
chef/node.json
{ "user": { "name": "deployer", "password": "$1$0wLEd9RQ$BHZn7Kyk4oarp4sVBxRt20", "ls_color": true }, "run_list": ["recipe[main]"] }
chef/cookbooks/main/recipes/default.rb
package "git-core" # apt-get install git-core package "zsh" include_recipe "nginx::source" user node[:user][:name] do password node[:user][:password] gid "admin" home "/home/#{node[:user][:name]}" supports manage_home: true shell "/bin/zsh" end template "/home/#{node[:user][:name]}/.zshrc" do source "zshrc.erb" owner node[:user][:name] end directory "/home/#{node[:user][:name]}/example" do owner node[:user][:name] end file "/home/#{node[:user][:name]}/example/index.html" do owner node[:user][:name] content "<h1>Hello World</h1>" end file "#{node[:nginx][:dir]}/sites-available/example" do content "server { root /home/#{node[:user][:name]}/example; }" end nginx_site "example"
chef/cookbooks/main/templates/default/zshrc.erb
export PS1='%m:%3~%# ' export RAILS_ENV=production <% if node[:user][:ls_color] %> alias ls='ls --color=auto' <% end %>