cluster_chef 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +51 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +63 -0
  4. data/Gemfile +18 -0
  5. data/LICENSE +201 -0
  6. data/README.md +332 -0
  7. data/Rakefile +92 -0
  8. data/TODO.md +8 -0
  9. data/VERSION +1 -0
  10. data/chefignore +41 -0
  11. data/cluster_chef.gemspec +115 -0
  12. data/clusters/website_demo.rb +65 -0
  13. data/config/client.rb +59 -0
  14. data/lib/cluster_chef/chef_layer.rb +297 -0
  15. data/lib/cluster_chef/cloud.rb +409 -0
  16. data/lib/cluster_chef/cluster.rb +118 -0
  17. data/lib/cluster_chef/compute.rb +144 -0
  18. data/lib/cluster_chef/cookbook_munger/README.md.erb +47 -0
  19. data/lib/cluster_chef/cookbook_munger/licenses.yaml +16 -0
  20. data/lib/cluster_chef/cookbook_munger/metadata.rb.erb +23 -0
  21. data/lib/cluster_chef/cookbook_munger.rb +588 -0
  22. data/lib/cluster_chef/deprecated.rb +33 -0
  23. data/lib/cluster_chef/discovery.rb +158 -0
  24. data/lib/cluster_chef/dsl_object.rb +123 -0
  25. data/lib/cluster_chef/facet.rb +144 -0
  26. data/lib/cluster_chef/fog_layer.rb +134 -0
  27. data/lib/cluster_chef/private_key.rb +110 -0
  28. data/lib/cluster_chef/role_implications.rb +49 -0
  29. data/lib/cluster_chef/security_group.rb +103 -0
  30. data/lib/cluster_chef/server.rb +265 -0
  31. data/lib/cluster_chef/server_slice.rb +259 -0
  32. data/lib/cluster_chef/volume.rb +93 -0
  33. data/lib/cluster_chef.rb +137 -0
  34. data/notes/aws_console_screenshot.jpg +0 -0
  35. data/rspec.watchr +29 -0
  36. data/spec/cluster_chef/cluster_spec.rb +13 -0
  37. data/spec/cluster_chef/facet_spec.rb +70 -0
  38. data/spec/cluster_chef/server_slice_spec.rb +19 -0
  39. data/spec/cluster_chef/server_spec.rb +112 -0
  40. data/spec/cluster_chef_spec.rb +193 -0
  41. data/spec/spec_helper/dummy_chef.rb +25 -0
  42. data/spec/spec_helper.rb +50 -0
  43. data/spec/test_config.rb +20 -0
  44. data/tasks/chef_config.rb +38 -0
  45. data/tasks/jeweler_use_alt_branch.rb +47 -0
  46. metadata +227 -0
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ ## OS
2
+ .DS_Store
3
+ Icon?
4
+ nohup.out
5
+
6
+ ## EDITORS
7
+ \#*
8
+ .#*
9
+ *~
10
+ *.swp
11
+ *.bak
12
+ REVISION
13
+ TAGS*
14
+ tmtags
15
+ *_flymake.*
16
+ *_flymake
17
+ *.tmproj
18
+ .project
19
+ .settings
20
+ mkmf.log
21
+
22
+ ## COMPILED
23
+ a.out
24
+ *.o
25
+ *.pyc
26
+ *.so
27
+
28
+ ## OTHER SCM
29
+ .bzr
30
+ .hg
31
+ .svn
32
+
33
+ ## PROJECT::GENERAL
34
+ coverage
35
+ rdoc
36
+ doc
37
+ pkg
38
+ .yardoc
39
+
40
+ ## PROJECT::SPECIFIC
41
+ .rvmrc
42
+ .vendor
43
+ .bundle
44
+ Gemfile.lock
45
+
46
+ .rake_test_cache
47
+ metadata.json
48
+ .chef
49
+ *.pem
50
+ .rvmrc
51
+ vendor/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --drb
data/CHANGELOG.md ADDED
@@ -0,0 +1,63 @@
1
+
2
+
3
+
4
+ ## Changes from v2 => v3 [2011 October]
5
+
6
+ **The below-described changes are still in progress**
7
+
8
+ _________
9
+
10
+ ClusterChef underwent a major upgrade with the last several commits.
11
+
12
+ * the `cluster_chef` tools -- the DSL, knife plugins, and bootstrap scripts -- have been split out of the [cluster_chef repo](http://github.com/infochimps/cluster_chef) into a [separate repo](http://github.com/infochimps/cluster_chef-tools).
13
+ * The tools are now available as a gem -- `gem install cluster_chef`
14
+ * Cleaned up the code
15
+ * Standardized clusters & roles
16
+ * Standardized cookbooks
17
+
18
+ ### ClusterChef DSL Changes
19
+
20
+ The following behaviors have been removed:
21
+
22
+ * `use` -- **BREAKING** Was supposed to let me import another cluster definition into the one calling use. However, it didn't work as advertised, was clutter-y and was actively unpopular (issue #6).
23
+ - Until the usage of derived clusters becomes clear, say `merge!` on a hash instead.
24
+ - We do default settings for you.
25
+ - We *don't* put in any default roles (as the old `use :defaults` did).
26
+
27
+ * `cloud` -- **BREAKING** a bare `cloud` statement is meaningless: the *attributes* may be abstract, but the *values* are different for every provider.
28
+ - Anywhere you used to say `cloud`, say `ec2`: eg `ec2.flavor('t1.micro')` instead of `cloud.flavor('t1.micro')`.
29
+
30
+ * `chef_attributes` -- **BREAKING** replaced by `facet_role.override_attributes`, `facet_role.default_attributes` (or those methods on `cluster_role`.)
31
+
32
+ * `cluster_role_implication` -- **BREAKING** now called role_implications, brought in by default.
33
+
34
+ * `cluster.mounts_ephemeral_volumes` is now `cloud.mount_ephemerals`; it is not done by default.
35
+
36
+ ### Knife Changes
37
+
38
+ Several knife scripts saw name changes to their params. If you have external scripts that call `knife cluster XXX` please update them. No futher changes to parameters are expected.
39
+
40
+ * `knife cluster kill` **only asks you once** whether to kill things -- there's no more `--really` flag.
41
+ * Standalone args now all properly have `--whatever` and `--no-whatever` forms.
42
+ * **BREAKING** The sync and kill commands both agree that `--chef` and `--cloud` are how to restrict their attention.
43
+
44
+
45
+ ### Cookbook-affecting changes
46
+
47
+ * Standardized on `node[:cluster_name]`, `node[:facet_name]` and `node[:facet_index]` as the way to refer to the cluster, facet and server parts of a node's name. This replaces the way-too-many names for these: `node[:cluster_chef][:facet]` and `node[:cluster_role]` (use `node[:facet_name]`), `node[:cluster_chef][:index]` and `node[:cluster_role_index]` (use `node[:facet_index]`) .
48
+ * ClusterChef family of cookbooks were updated accordingly.
49
+
50
+ #### hadoop_cluster cookbook
51
+
52
+ * The bootstrap recipes are gone. They may come back, but for now the dance is:
53
+ - bring up the cluster ; by default the service state for all the daemons is [:disable, :stop].
54
+ - run the `/etc/hadoop/conf/bootstrap_hadoop_namenode.sh` to format your HDFS
55
+ - move the service state to '[:enable, :start]' and re-run chef client
56
+
57
+
58
+ #### Deprecated cookbooks
59
+
60
+ You must add `"#{cluster_chef_path}/deprecated-cookbooks"` to your cookbook_path in knife.rb if you would like to keep using
61
+
62
+ * `cluster_ebs_volumes` -- use `mountable_volumes` instead.
63
+
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'chef', "~> 0.10.4"
4
+ gem 'fog', "~> 1.1.1"
5
+ gem 'formatador', "~> 0.2.1"
6
+ gem 'gorillib', "~> 0.1.7"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem 'bundler', "~> 1"
12
+ gem 'yard', "~> 0.6.7"
13
+ gem 'jeweler', "~> 1.6.4"
14
+ gem 'rspec', "~> 2.7.0"
15
+ gem 'configliere', "~> 0.4.8"
16
+ gem 'spork', "~> 0.9.0.rc5"
17
+ gem 'watchr', "~> 0.7"
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,332 @@
1
+ # cluster_chef
2
+
3
+ Chef is a powerful tool for maintaining and describing the software and configurations that let a machine provide its services.
4
+
5
+ cluster_chef is
6
+
7
+ * a clean, expressive way to describe how machines and roles are assembled into a working cluster.
8
+ * Our collection of Industrial-strength, cloud-ready recipes for Hadoop, Cassandra, HBase, Elasticsearch and more.
9
+ * a set of conventions and helpers that make provisioning cloud machines easier.
10
+
11
+ ## Walkthrough
12
+
13
+ Here's a very simple cluster:
14
+
15
+
16
+ ```ruby
17
+ ClusterChef.cluster 'awesome' do
18
+ cloud(:ec2) do
19
+ flavor 't1.micro'
20
+ end
21
+
22
+ role :base_role
23
+ role :chef_client
24
+ role :ssh
25
+
26
+ # The database server
27
+ facet :dbnode do
28
+ instances 1
29
+ role :mysql_server
30
+
31
+ cloud do
32
+ flavor 'm1.large'
33
+ backing 'ebs'
34
+ end
35
+ end
36
+
37
+ # A throwaway facet for development.
38
+ facet :webnode do
39
+ instances 2
40
+ role :nginx_server
41
+ role :awesome_webapp
42
+ end
43
+ end
44
+ ```
45
+
46
+ This code defines a cluster named demosimple. A cluster is a group of servers united around a common purpose, in this case to serve a scalable web application.
47
+
48
+ The awesome cluster has two 'facets' -- dbnode and webnode. A facet is a subgroup of interchangeable servers that provide a logical set of systems: in this case, the systems that store the website's data and those that render it.
49
+
50
+ The dbnode facet has one server, which will be named 'awesome-dbnode-0'; the webnode facet has two servers, 'awesome-webnode-0' and 'awesome-webnode-1'.
51
+
52
+ Each server inherits the appropriate behaviors from its facet and cluster. All the servers in this cluster have the `base_role`, `chef_client` and `ssh` roles. The dbnode machines additionally house a MySQL server, while the webnodes have an nginx reverse proxy for the custom `awesome_webapp`.
53
+
54
+ As you can see, the dbnode facet asks for a different flavor of machine ('m1.large') than the cluster default ('t1.micro'). Settings in the facet override those in the server, and settings in the server override those of its facet. You economically describe only what's significant about each machine.
55
+
56
+ ### Cluster-level tools
57
+
58
+
59
+ ```
60
+ $ knife cluster show awesome
61
+
62
+ +--------------------+-------+------------+-------------+--------------+---------------+-----------------+----------+--------------+------------+------------+
63
+ | Name | Chef? | InstanceID | State | Public IP | Private IP | Created At | Flavor | Image | AZ | SSH Key |
64
+ +--------------------+-------+------------+-------------+--------------+---------------+-----------------+----------+--------------+------------+------------+
65
+ | awesome-dbnode-0 | yes | i-43c60e20 | running | 107.22.6.104 | 10.88.112.201 | 20111029-204156 | t1.micro | ami-cef405a7 | us-east-1a | awesome |
66
+ | awesome-webnode-0 | yes | i-1233aef1 | running | 102.99.3.123 | 10.88.112.123 | 20111029-204156 | t1.micro | ami-cef405a7 | us-east-1a | awesome |
67
+ | awesome-webnode-1 | yes | i-0986423b | not running | | | | | | | |
68
+ +--------------------+-------+------------+-------------+--------------+---------------+-----------------+----------+--------------+------------+------------+
69
+
70
+
71
+ ```
72
+
73
+ The commands available are
74
+ * list -- lists known clusters
75
+ * show -- show the named servers
76
+ * launch -- launch server
77
+ * bootstrap
78
+ * sync
79
+ * ssh
80
+ * start/stop
81
+ * kill
82
+ * kick -- trigger a chef-client run on each named machine, tailing the logs until the run completes
83
+
84
+
85
+ ### Advanced clusters remain simple
86
+
87
+ Let's say that app is truly awesome, and the features and demand increases. This cluster adds an [ElasticSearch server](http://elasticsearch.org) for searching, a haproxy loadbalancer, and spreads the webnodes across two availability zones.
88
+
89
+ ```ruby
90
+ ClusterChef.cluster 'webserver_demo' do
91
+ cloud(:ec2) do
92
+ image_name "maverick"
93
+ flavor "t1.micro"
94
+ availability_zones ['us-east-1a']
95
+ end
96
+
97
+ # The database server
98
+ facet :dbnode do
99
+ instances 1
100
+ role :mysql_server
101
+ cloud do
102
+ flavor 'm1.large'
103
+ backing 'ebs'
104
+ end
105
+
106
+ volume(:data) do
107
+ size 20
108
+ keep true
109
+ device '/dev/sdi'
110
+ mount_point '/data'
111
+ snapshot_id 'snap-a10234f'
112
+ attachable :ebs
113
+ end
114
+ end
115
+
116
+ facet :webnode do
117
+ instances 6
118
+ cloud.availability_zones ['us-east-1a', 'us-east-1b']
119
+
120
+ role :nginx_server
121
+ role :awesome_webapp
122
+ role :elasticsearch_client
123
+
124
+ volume(:server_logs) do
125
+ size 5
126
+ keep true
127
+ device '/dev/sdi'
128
+ mount_point '/server_logs'
129
+ snapshot_id 'snap-d9c1edb1'
130
+ end
131
+ end
132
+
133
+ facet :esnode do
134
+ instances 1
135
+ role "elasticsearch_data_esnode"
136
+ role "elasticsearch_http_esnode"
137
+ cloud.flavor "m1.large"
138
+ end
139
+
140
+ facet :loadbalancer do
141
+ instances 1
142
+ role "haproxy"
143
+ cloud.flavor "m1.xlarge"
144
+ elastic_ip "128.69.69.23"
145
+ end
146
+
147
+ cluster_role.override_attributes({
148
+ :elasticsearch => {
149
+ :version => '0.17.8',
150
+ },
151
+ })
152
+ end
153
+ ```
154
+
155
+ The facets are described and scale independently. If you'd like to add more webnodes, just increase the instance count. If a machine misbehaves, just terminate it. Running `knife cluster launch awesome webnode` will note which machines are missing, and launch and configure them appropriately.
156
+
157
+ ClusterChef speaks naturally to both Chef and your cloud provider. The esnode's `cluster_role.override_attributes` statement will be synchronized to the chef server, pinning the elasticsearch version across the clients and server.. Your chef roles should focus system-specific information; the cluster file lets you see the architecture as a whole.
158
+
159
+ With these simple settings, if you have already [set up chef's knife to launch cloud servers](http://wiki.opscode.com/display/chef/Launch+Cloud+Instances+with+Knife), typing `knife cluster launch demosimple --bootstrap` will (using Amazon EC2 as an example):
160
+
161
+ * Synchronize to the chef server:
162
+ - create chef roles on the server for the cluster and each facet.
163
+ - apply role directives (eg the homebase's `default_attributes` declaration).
164
+ - create a node for each machine
165
+ - apply the runlist to each node
166
+ * Set up security isolation:
167
+ - uses a keypair (login ssh key) isolated to that cluster
168
+ - Recognizes the `ssh` role, and add a security group `ssh` that by default opens port 22.
169
+ - Recognize the `nfs_server` role, and adds security groups `nfs_server` and `nfs_client`
170
+ - Authorizes the `nfs_server` to accept connections from all `nfs_client`s. Machines in other clusters that you mark as `nfs_client`s can connect to the NFS server, but are not automatically granted any other access to the machines in this cluster. ClusterChef's opinionated behavior is about more than saving you effort -- tying this behavior to the chef role means you can't screw it up.
171
+ * Launches the machines in parallel:
172
+ - using the image name and the availability zone, it determines the appropriate region, image ID, and other implied behavior.
173
+ - passes a JSON-encoded user_data hash specifying the machine's chef `node_name` and client key. An appropriately-configured machine image will need no further bootstrapping -- it will connect to the chef server with the appropriate identity and proceed completely unattended.
174
+ * Syncronizes to the cloud provider:
175
+ - Applies EC2 tags to the machine, making your console intelligible: ![AWS Console screenshot](https://github.com/infochimps/cluster_chef/raw/version_3/notes/aws_console_screenshot.jpg)
176
+ - Connects external (EBS) volumes, if any, to the correct mount point -- it uses (and applies) tags to the volumes, so they know which machine to adhere to. If you've manually added volumes, just make sure they're defined correctly in your cluster file and run `knife cluster sync {cluster_name}`; it will paint them with the correct tags.
177
+ - Associates an elastic IP, if any, to the machine
178
+ * Bootstraps the machine using knife bootstrap
179
+
180
+ ---------------------------------------------------------------------------
181
+
182
+ ## Getting Started
183
+
184
+ This assumes you have installed chef, have a working chef server, and have an AWS account. If you can run knife and use the web browser to see your EC2 console, you can start here. If not, see the instructions below.
185
+
186
+ ### Setup
187
+
188
+ ```ruby
189
+ bundle install
190
+ ```
191
+
192
+ ### Your first cluster
193
+
194
+ Let's create a cluster called 'demosimple'. It's, well, a simple demo cluster.
195
+
196
+ #### Create a simple demo cluster
197
+
198
+ Create a directory for your clusters; copy the demosimple cluster and its associated roles from cluster_chef:
199
+
200
+ ```ruby
201
+ mkdir -p $CHEF_REPO_DIR/clusters
202
+ cp cluster_chef/clusters/{defaults,demosimple}.rb ./clusters/
203
+ cp cluster_chef/roles/{big_package,nfs_*,ssh,base_role,chef_client}.rb ./roles/
204
+ ```
205
+
206
+ Lastly, add the `cookbooks`, `site-cookbooks`, and `meta-cookbooks` directories
207
+ from cluster_chef to the `cookbooks_path` in your knife.rb, and push everything
208
+ to the chef server. (see below for details).
209
+
210
+ #### knife cluster launch
211
+
212
+ Hooray! You're ready to launch a cluster:
213
+
214
+ ```ruby
215
+ knife cluster launch demosimple homebase --bootstrap
216
+ </pre>
217
+
218
+ It will kick off a node and then bootstrap it. You'll see it install a whole bunch of things. Yay.
219
+
220
+ __________________________________________________________________________
221
+
222
+ ## Philosophy
223
+
224
+ Some general principles of how we use chef.
225
+
226
+ * *Chef server is never the repository of truth* -- it only mirrors the truth.
227
+ - a file is tangible and immediate to access
228
+ * Specifically, we want truth to live in the git repo, and be enforced by the chef server. *There is no truth but git, and chef is its messenger*.
229
+ - this means that everything is versioned, documented and exchangeable.
230
+ * *Systems, services and significant modifications cluster should be obvious from the `clusters` file*. I don't want to have to bounce around nine different files to find out which thing installed a redis:server.
231
+ - basically, the existence of anything that opens a port should be obvious when I look at the cluster file.
232
+ * *Roles define systems, clusters assemble systems into a machine*.
233
+ - For example, a resque worker queue has a redis, a webserver and some config files -- your cluster should invoke a @whatever_queue@ role, and the @whatever_queue@ role should include recipes for the component services.
234
+ - the existence of anything that opens a port _or_ runs as a service should be obvious when I look at the roles file.
235
+ * *include_recipe considered harmful* Do NOT use include_recipe for anything that a) provides a service, b) launches a daemon or c) is interesting in any way. (so: @include_recipe java@ yes; @include_recipe iptables@ no.) You should note the dependency in the metadata.rb. This seems weird, but the breaking behavior is purposeful: it makes you explicitly state all dependencies.
236
+ * It's nice when *machines are in full control of their destiny*.
237
+ - initial setup (elastic IP, attaching a drive) is often best enforced externally
238
+ - but machines should be ablt independently assert things like load balancer registration that that might change at any point in the lifetime.
239
+ * It's even nicer, though, to have *full idempotency from the command line*: I can at any time push truth from the git repo to the chef server and know that it will take hold.
240
+
241
+ __________________________________________________________________________
242
+
243
+ ## Advanced Superpowers
244
+
245
+ #### Auto-vivifying machines (no bootstrap required!)
246
+
247
+ On EC2, you can make a machine that auto-vivifies -- no bootstrap necessary. Burn an AMI that has the `config/client.rb` file in /etc/chef/client.rb. It will use the ec2 userdata (passed in by knife) to realize its purpose in life, its identity, and the chef server to connect to; everything happens automagically from there. No parallel ssh required!
248
+
249
+ #### EBS Volumes
250
+
251
+ Define a `snapshot_id` for your volumes, and set `create_at_launch` true.
252
+
253
+ __________________________________________________________________________
254
+
255
+
256
+ ## Extended Installation Notes
257
+
258
+ #### Set up Knife on your local machine, and a Chef Server in the cloud
259
+
260
+ If you already have a working chef installation you can skip this section.
261
+
262
+ To get started with knife and chef, follow the "Chef Quickstart,":http://wiki.opscode.com/display/chef/Quick+Start We use the hosted chef service and are very happy, but there are instructions on the wiki to set up a chef server too. Stop when you get to "Bootstrap the Ubuntu system" -- cluster chef is going to make that much easier.
263
+
264
+ #### Cloud setup
265
+
266
+ Next,
267
+
268
+ * sign up for an AWS account
269
+ * Follow the "Knife with AWS quickstart": on the opscode wiki.
270
+
271
+ Right now cluster chef works well with AWS. If you're interested in modifying it to work with other cloud providers, "see here":https://github.com/infochimps/cluster_chef/issues/28 or get in touch.
272
+
273
+ #### Knife setup
274
+
275
+ In your `.chef/knife.rb`, modify the cookbook path to include cluster_chef's `cookbooks`, `meta-cookbooks` and `site-cookbooks`, and to add settings for `cluster_chef_path`, `cluster_path` and `keypair_path`. Here's mine:
276
+
277
+ ```
278
+ current_dir = File.dirname(__FILE__)
279
+ organization = 'CHEF_ORGANIZATION'
280
+ username = 'CHEF_USERNAME'
281
+
282
+ # The full path to your cluster_chef installation
283
+ cluster_chef_path File.expand_path("#{current_dir}/../cluster_chef")
284
+ # The list of paths holding clusters
285
+ cluster_path [ File.expand_path("#{current_dir}/../clusters") ]
286
+ # The directory holding your cloud keypairs
287
+ keypair_path File.expand_path(current_dir)
288
+
289
+ log_level :info
290
+ log_location STDOUT
291
+ node_name username
292
+ client_key "#{keypair_path}/#{username}.pem"
293
+ validation_client_name "#{organization}-validator"
294
+ validation_key "#{keypair_path}/#{organization}-validator.pem"
295
+ chef_server_url "https://api.opscode.com/organizations/#{organization}"
296
+ cache_type 'BasicFile'
297
+ cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
298
+
299
+ # The first things have lowest priority (so, site-cookbooks gets to win)
300
+ cookbook_path [
301
+ "#{cluster_chef_path}/cookbooks", # std cookbooks from opscode/cookbooks
302
+ "#{cluster_chef_path}/meta-cookbooks", # coordinate services among cookbooks
303
+ "#{cluster_chef_path}/site-cookbooks", # infochimps' collection of cookbooks
304
+ "#{current_dir}/../cookbooks",
305
+ "#{current_dir}/../site-cookbooks", # your internal cookbooks
306
+ ]
307
+
308
+ # If you primarily use AWS cloud services:
309
+ knife[:ssh_address_attribute] = 'cloud.public_hostname'
310
+ knife[:ssh_user] = 'ubuntu'
311
+
312
+ # Configure bootstrapping
313
+ knife[:bootstrap_runs_chef_client] = true
314
+ bootstrap_chef_version "~> 0.10.0"
315
+
316
+ # AWS access credentials
317
+ knife[:aws_access_key_id] = "XXXXXXXXXXX"
318
+ knife[:aws_secret_access_key] = "XXXXXXXXXXXXX"
319
+ ```
320
+
321
+ #### Push to chef server
322
+
323
+ To send all the cookbooks and role to the chef server, visit your cluster_chef directory and run:
324
+
325
+ ```ruby
326
+ cd $CHEF_REPO_DIR
327
+ mkdir -p $CHEF_REPO_DIR/site-cookbooks
328
+ knife cookbook upload --all
329
+ for foo in roles/*.rb ; do knife role from file $foo & sleep 1 ; done
330
+ ```
331
+
332
+ You should see all the cookbooks defined in cluster_chef/cookbooks (ant, apt, ...) listed among those it uploads.