Cheat Sheet速查表
跳转到主要内容

Chef 速查表

本文根据 Devhints / Chef 翻译。代码示例及版本范围沿用原文。

安装

在您的服务器上:

$ 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

启动 cookbook

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

Knife

$ knife supermarket download mysql

调用 chef-solo

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

示例

简单的从源码编译

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)

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

ruby_block

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

执行

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

条件

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

另请参阅