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