Cooking environments with chef

2,803 views

Published on

Published in: Technology, Self Improvement
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,803
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Cooking environments with chef

  1. 1. Cooking Environments with Chef<br />
  2. 2. Everything begins with a plan<br />What<br />Why<br />How<br />@colin_gemmell pythonandchips@gmail.com<br />
  3. 3. What’s it for<br />Born out of “cloud computing” and dev-ops<br />Cross platform Configuration and deployment tool written in ruby<br />Execute OS commands<br />Focuses on reusable recipes<br />@colin_gemmell pythonandchips@gmail.com<br />
  4. 4. Termanology<br />Resource – Executable bit of code<br />Recipe – Collection of resources<br />Cookbook – recipes and all other files need for to complete a task<br />@colin_gemmell pythonandchips@gmail.com<br />
  5. 5. Why<br />Allows configuration of every environment the same <br />Version Control your configurations<br />Not just for servers<br />@colin_gemmell pythonandchips@gmail.com<br />
  6. 6. How<br />2 different flavours of chef<br />Chef Server & Chef Client<br />Chef Solo<br />Bootstrap the environment<br />Configuration file<br />Main recipe<br />Resources<br />@colin_gemmell pythonandchips@gmail.com<br />
  7. 7. Package<br />Install application from package manager<br />package "couchdb" do<br />package_name "couchdb"<br />end<br />@colin_gemmell pythonandchips@gmail.com<br />
  8. 8. Template<br />Generate file based on an erb template<br />template "/home/cgemmell/.gitconfig" do<br /> source "gitconfig.erb"<br /> owner node[:user]<br /> group node[:user]<br /> mode "0644"<br /> variables(<br /> :name => node["name"],<br /> :email => node["email"]<br /> )<br />end<br />@colin_gemmell pythonandchips@gmail.com<br />
  9. 9. Template<br />File: gitconfig.erb<br />[user]<br /> name = <%= @name %><br /> email = <%= @email %><br />[diff]<br /> external = kdiff3<br />[pager]<br /> diff =<br />[merge]<br /> tool = kdiff3<br />@colin_gemmell pythonandchips@gmail.com<br />
  10. 10. Creating files and directories<br />directory “/home/cgemmell/projects" do<br /> owner node[:user]<br /> group node[:user]<br /> mode "0755"<br /> action :create<br />end<br />file "/home/#{node[:user]}/.bashrc" do<br /> group node[:user]<br /> owner node[:user]<br /> mode "0644"<br /> content "source .bashrvm"<br /> action :create<br />not_if do<br />File.exists?("/home/cgemmell/.bashrc")<br /> end<br />end<br />@colin_gemmell pythonandchips@gmail.com<br />
  11. 11. Execute script<br />bash "install coffeescript" do<br /> interpreter "bash"<br /> user "root"<br />cwd “/home/cgemmell”<br /> code “npm install -g coffee-script”<br />end<br />@colin_gemmell pythonandchips@gmail.com<br />
  12. 12. Download remote file<br />remote_file “/tmp/RubyMine-3.1.1.tar.gz" do<br /> source "http://download.jetbrains.com/ruby/RubyMine-3.1.1.tar.gz"<br />end<br />@colin_gemmell pythonandchips@gmail.com<br />
  13. 13. Checkout from Source control<br />git “/home/cgemmell/projects/chef" do<br /> user node[:user]<br /> group node[:user]<br /> repository “git@github.com:opscode/chef”<br /> reference "master"<br /> action :sync<br /> end<br />@colin_gemmell pythonandchips@gmail.com<br />
  14. 14. Chef on windows<br />Not fully supported<br />Manual installation a bit complicated<br />Installer available at<br />https://github.com/downloads/pmorton/chef-windows-installer/ChefInstaller.exe<br />More info avaiable at<br />http://wiki.opscode.com/display/chef/Installation+on+Windows<br />@colin_gemmell pythonandchips@gmail.com<br />
  15. 15. Powershell<br />Powershell “cwd-then-write” do<br />cwd “temp”<br />code <<-EOH<br /> $stream = [System.IO.StreamWriter] “./temp-write-from-chef.txt”<br /> $stream.WriteLine(“Chef on windows is awesome”)<br /> $stream.close()<br />EOH<br />end<br />N.B. Dependant on the powershell<br />@colin_gemmell pythonandchips@gmail.com<br />
  16. 16. The end<br />Resources<br />Documentation<br />http://wiki.opscode.com/display/chef/Home<br />Source code<br />https://github.com/opscode/chef<br />Pre-written recipes<br />https://github.com/opscode/cookbooks<br />VM Setup<br />https://github.com/pythonandchips/chef-vm-setup<br />Twitter: @colin_gemmell<br />E-mail: pythonandchips@gmail.com<br />@colin_gemmell pythonandchips@gmail.com<br />

×