Chef Cheat Sheet

From WikiOD

Here is the cheatsheat of Chef and basic guide on how to use Chef

Install[edit | edit source]

In your server: {: .-setup}

$ sudo apt-get install curl
$ curl -L https://omnitruck.chef.io/install.sh | sudo bash
Thank you for installing Chef!
$ chef-solo -v
...
Chef: 14.5.33

Start the cookbook[edit | edit source]

 wget http://github.com/chef-cookbooks/chef-repo/tarball/master -O - | tar xzf - --strip-components=1

Knife[edit | edit source]

$ knife supermarket download mysql

Invoking chef-solo[edit | edit source]

$ chef-solo -c solo.rb -j web.json

Examples[edit | edit source]

Simple compile-from-source[edit | edit source]

execute "tar --no-same-owner -zxf hi.tar.gz" do
  cwd "/usr/local/src"
  creates "/usr/local/src/node-v#{version}"
end
bash "compile" do
  cwd "/usr/local/src/node-v#{version}"
  code %[
    PATH=/usr/local/bin:$PATH
    ./configure
    make
  ]
  creates "/usr/local/src/node-v#{version}/node"
end

remote file[edit | edit source]

remote_file "/usr/local/src/hi.tar.gz" do
  source "http://..."
  checksum "ab83be..."
  mode 0644
  action :create_if_missing
end

ruby_block[edit | edit source]

ruby_block "name" do
  block { File.read ... }
  not_if { File.exists?(...) }
end

Execute[edit | edit source]

execute "name" do
  cwd "..."
  environment({ "PATH" => "..." })
  command "make install"
  creates "..."
end

Conditions[edit | edit source]

  creates "/usr/local/src/node-v#{version}/node"
  not_if { File.exists?('...') }

Also see[edit | edit source]

Credit:rstacruz