OSDN Git Service

Regular updates
[twpd/master.git] / chef.md
1 ---
2 title: Chef
3 category: Devops
4 layout: 2017/sheet
5 ---
6
7 ### Install
8
9 In your server:
10 {: .-setup}
11
12 ```bash
13 $ sudo apt-get install curl
14 ```
15
16 ```bash
17 $ curl -L https://omnitruck.chef.io/install.sh | sudo bash
18 Thank you for installing Chef!
19 ```
20
21 ```bash
22 $ chef-solo -v
23 ...
24 Chef: 14.5.33
25 ```
26
27 ### Start the cookbook
28
29 ```bash
30  wget http://github.com/chef-cookbooks/chef-repo/tarball/master -O - | tar xzf - --strip-components=1
31 ```
32
33 ### Knife
34
35 ```bash
36 $ knife supermarket download mysql
37 ```
38
39 ### Invoking chef-solo
40
41 ```bash
42 $ chef-solo -c solo.rb -j web.json
43 ```
44
45 ## Examples
46
47 ### Simple compile-from-source
48
49 ```ruby
50 execute "tar --no-same-owner -zxf hi.tar.gz" do
51   cwd "/usr/local/src"
52   creates "/usr/local/src/node-v#{version}"
53 end
54 ```
55
56 ```ruby
57 bash "compile" do
58   cwd "/usr/local/src/node-v#{version}"
59   code %[
60     PATH=/usr/local/bin:$PATH
61     ./configure
62     make
63   ]
64   creates "/usr/local/src/node-v#{version}/node"
65 end
66 ```
67
68 ### remote file
69
70 ```ruby
71 remote_file "/usr/local/src/hi.tar.gz" do
72   source "http://..."
73   checksum "ab83be..."
74   mode 0644
75   action :create_if_missing
76 end
77 ```
78
79 ### ruby_block
80
81 ```ruby
82 ruby_block "name" do
83   block { File.read ... }
84   not_if { File.exists?(...) }
85 end
86 ```
87
88 ### Execute
89
90 ```ruby
91 execute "name" do
92   cwd "..."
93   environment({ "PATH" => "..." })
94   command "make install"
95   creates "..."
96 end
97 ```
98
99 ### Conditions
100
101 ```ruby
102   creates "/usr/local/src/node-v#{version}/node"
103   not_if { File.exists?('...') }
104 ```
105
106 ## Also see
107
108 * [Learn Chef Rally](https://learn.chef.io) _(learn.chef.io)_
109 * [install_from_source.rb recipe](https://github.com/mdxp/nodejs-cookbook/blob/master/recipes/install_from_source.rb) _(github.com)_