16
Cooking Environments with Chef

Cooking environments with chef

Embed Size (px)

Citation preview

Page 1: Cooking environments with chef

Cooking Environments with Chef

Page 2: Cooking environments with chef

@colin_gemmell [email protected]

Everything begins with a plan

•What•Why• How

Page 3: 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

Page 4: Cooking environments with chef

@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

Page 5: Cooking environments with chef

@colin_gemmell [email protected]

Why

• Allows configuration of every environment the same

• Version Control your configurations• Not just for servers

Page 6: Cooking environments with chef

@colin_gemmell [email protected]

How

• 2 different flavours of chef– Chef Server & Chef Client– Chef Solo

• Bootstrap the environment• Configuration file• Main recipe• Resources

Page 7: Cooking environments with chef

@colin_gemmell [email protected]

Package

• Install application from package manager

package "couchdb" do package_name "couchdb"end

Page 8: Cooking environments with chef

@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

Page 9: Cooking environments with chef

@colin_gemmell [email protected]

Template

File: gitconfig.erb

[user] name = <%= @name %> email = <%= @email %>[diff] external = kdiff3[pager] diff =[merge]

tool = kdiff3

Page 10: Cooking environments with chef

@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

Page 11: Cooking environments with chef

@colin_gemmell [email protected]

Execute script

bash "install coffeescript" do interpreter "bash" user "root" cwd “/home/cgemmell” code “npm install -g coffee-script”end

Page 12: Cooking environments with chef

@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

Page 13: Cooking environments with chef

@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

Page 14: Cooking environments with chef

@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

Page 15: Cooking environments with chef

@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

Page 16: Cooking environments with chef

@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]