ironfan 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +51 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +130 -0
  4. data/Gemfile +26 -0
  5. data/LICENSE.md +201 -0
  6. data/README.md +328 -0
  7. data/Rakefile +104 -0
  8. data/TODO.md +16 -0
  9. data/VERSION +1 -0
  10. data/chefignore +41 -0
  11. data/cluster_chef-knife.gemspec +123 -0
  12. data/cluster_chef.gemspec +111 -0
  13. data/config/client.rb +59 -0
  14. data/config/proxy.pac +12 -0
  15. data/config/ubuntu10.04-ironfan.erb +157 -0
  16. data/config/ubuntu11.10-ironfan.erb +145 -0
  17. data/ironfan.gemspec +121 -0
  18. data/lib/chef/knife/bootstrap/ubuntu10.04-ironfan.erb +157 -0
  19. data/lib/chef/knife/bootstrap/ubuntu11.10-ironfan.erb +145 -0
  20. data/lib/chef/knife/cluster_bootstrap.rb +74 -0
  21. data/lib/chef/knife/cluster_kick.rb +94 -0
  22. data/lib/chef/knife/cluster_kill.rb +73 -0
  23. data/lib/chef/knife/cluster_launch.rb +164 -0
  24. data/lib/chef/knife/cluster_list.rb +50 -0
  25. data/lib/chef/knife/cluster_proxy.rb +126 -0
  26. data/lib/chef/knife/cluster_show.rb +61 -0
  27. data/lib/chef/knife/cluster_ssh.rb +141 -0
  28. data/lib/chef/knife/cluster_start.rb +40 -0
  29. data/lib/chef/knife/cluster_stop.rb +43 -0
  30. data/lib/chef/knife/cluster_sync.rb +77 -0
  31. data/lib/chef/knife/generic_command.rb +66 -0
  32. data/lib/chef/knife/knife_common.rb +195 -0
  33. data/lib/ironfan.rb +143 -0
  34. data/lib/ironfan/chef_layer.rb +299 -0
  35. data/lib/ironfan/cloud.rb +412 -0
  36. data/lib/ironfan/cluster.rb +118 -0
  37. data/lib/ironfan/compute.rb +153 -0
  38. data/lib/ironfan/deprecated.rb +33 -0
  39. data/lib/ironfan/discovery.rb +177 -0
  40. data/lib/ironfan/dsl_object.rb +124 -0
  41. data/lib/ironfan/facet.rb +144 -0
  42. data/lib/ironfan/fog_layer.rb +150 -0
  43. data/lib/ironfan/private_key.rb +130 -0
  44. data/lib/ironfan/role_implications.rb +58 -0
  45. data/lib/ironfan/security_group.rb +119 -0
  46. data/lib/ironfan/server.rb +281 -0
  47. data/lib/ironfan/server_slice.rb +260 -0
  48. data/lib/ironfan/volume.rb +157 -0
  49. data/spec/ironfan/cluster_spec.rb +13 -0
  50. data/spec/ironfan/facet_spec.rb +69 -0
  51. data/spec/ironfan/server_slice_spec.rb +19 -0
  52. data/spec/ironfan/server_spec.rb +112 -0
  53. data/spec/ironfan_spec.rb +193 -0
  54. data/spec/spec_helper.rb +50 -0
  55. data/spec/spec_helper/dummy_chef.rb +25 -0
  56. data/spec/test_config.rb +20 -0
  57. data/tasks/chef_config.rake +38 -0
  58. data/tasks/jeweler_use_alt_branch.rake +53 -0
  59. metadata +217 -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,130 @@
1
+ # v3.1.0-rc1
2
+
3
+ * 'ClusterChef has been renamed 'Ironfan'
4
+ * The 'Metachef' cookbook has been renamed 'Silverware'
5
+ * The 'Minidash' cookbook has been renamed 'Minidash'
6
+
7
+ Please be sure you do a
8
+
9
+ knife cookbook delete metachef minidash
10
+ knife cookbook upload --all
11
+
12
+ These renames unfortunately hit every cookbook that depends on (what is now) silverware.
13
+
14
+ __________________________________________________________________________
15
+ __________________________________________________________________________
16
+
17
+ ## v3.0.14:
18
+
19
+ Big important change:
20
+
21
+ # Ironfan is now Ironfan
22
+
23
+ Due to a polite request from outside, we are changing this project's name to not include the word 'Chef'.
24
+
25
+ It's now 'Ironfan', after Princess Iron Fan from the legend of Sun Wukong (Voyage to the West). The monkey hero Sun Wukong could not reach his destination without the help of the Princess's Iron Fan. The project helps you fan out across big iron in the sky -- and "You Can't Do B.I. without a Big Ironfan".
26
+
27
+ This weekend (2/18) everything in the ironfan family of everything will get regex-replaced as ironfan. We'll track both gems for the next push or so, but new versions of the gem will not be released after Feb 2012.
28
+
29
+ Other improvements/fixes:
30
+
31
+ * knife cluster proxy now accepts additional hosts to direct to proxy -- set Chef::Config[:cluster_proxy_patterns] to an array of additional glob-style strings. Use this with the route53 support for fun and profit - if your machines look like foo-server-0-internal.whatupchimpy.com, add Chef::Config[:cluster_proxy_patterns] = '*internal.whatupchimpy.com*' to your knife-org.rb -- now you can browse securely to the private interface of any machine your target can.
32
+ * FIX #76 -- `knife cluster kick` runs chef-client if the service is stopped. Fixes #76 . Also knife ssh will at its end show a bright red list of machines whose commands exited with a non-zero exit code -- useful when 1 out of 30 machines fails a knife cluster kick.
33
+ * A limited number of commands (ssh, show, kill) now run with no requirement of cloud anything (Relates to #28). Also worked around an annoying incompatibility with chef 0.10.8 (clients have a 'name') vs 0.10.40-and-prev (clients have a 'clientname'.
34
+ * examples all live in `ironfan-homebase` now.
35
+ * When you `knife cluster stop` a node, it sets `node[:state]` to
36
+ * the cookbook linter now has its own project: [ironfan-scrubby](https://github.com/infochimps-labs/ironfan-scrubby). Along the way,
37
+ - some ability to cycle comments from the attributes file into node attribute docs in the `metadata.rb`.
38
+ - added helpful links to the `README.md` template
39
+ * minor fix to the new `authorized_by` calls
40
+
41
+ ## v3.0.11: We Raid at Dawn
42
+
43
+ * You can now assemble raid groups in the cluster definition:
44
+ - node metadata instructing the volumes recipe to build the raid volume
45
+ - marks the component volumes as non-mountable, in the appropriate raid group, etc
46
+ * Changed the order of `cluster_role` and `facet_role` in the run list. It now goes:
47
+ - `:first` roles (cluster then facet)
48
+ - `:normal` roles (cluster then facet)
49
+ - special roles: `cluster_role` then `facet_role`
50
+ - `:last` roles (cluster then facet)
51
+ * knife cluster launch uses ClusterBootstrap, not knife's vanilla bootstrap.
52
+ * can now do group('group_that_wants').authorized_by_group('group_that_grants') so that in cluster A I can request access to cluster B without gaining its group myself.
53
+ * push the organization (if set) into the node metadata
54
+
55
+ ## v3.0.10: Cloud fixes
56
+
57
+ * security groups are now created/updated in knife cluster sync. This can't help you apply then to a node afer launch though -- nothing can, the API doesn't allow it.
58
+ * clusters now all refer to an AMI named `ironfan-natty` by default, and to customizable roles `org_base`, `org_final` and `org_users` (where `org_base` has a role_implication for membership in the systemwide `org_base` security group)
59
+ * default facet instances is now 1 who knows why it wasn't always 1.
60
+ * minor linting of cluster before launching it
61
+ * bump to latest versions of oneiric AMIs thx @redbeard
62
+ * bootstrap fixes, oneiric support, more from @gchpaco
63
+
64
+
65
+ ## v3.0.6: schism of cookbooks and tools
66
+
67
+ * cookbooks all now live in [their own repo](https://github.com/infochimps-labs/ironfan-homebase), organized according to opscode standard.
68
+ * gem is now split into `ironfan` (the libraries) and `ironfan-knife` (the chef plugins)
69
+ * private_key was passing its block to super, with bad results
70
+
71
+ ## Changes from v2 => v3 [2011 October]
72
+
73
+ **The below-described changes are still in progress**
74
+
75
+ _________
76
+
77
+ Ironfan underwent a major upgrade with the last several commits.
78
+
79
+ * the `ironfan` tools -- the DSL, knife plugins, and bootstrap scripts -- have been split out of the [ironfan repo](http://github.com/infochimps-labs/ironfan) into a [separate repo](http://github.com/infochimps-labs/ironfan-tools).
80
+ * The tools are now available as a gem -- `gem install ironfan`
81
+ * Cleaned up the code
82
+ * Standardized clusters & roles
83
+ * Standardized cookbooks
84
+
85
+ ### Ironfan DSL Changes
86
+
87
+ The following behaviors have been removed:
88
+
89
+ * `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).
90
+ - Until the usage of derived clusters becomes clear, say `merge!` on a hash instead.
91
+ - We do default settings for you.
92
+ - We *don't* put in any default roles (as the old `use :defaults` did).
93
+
94
+ * `cloud` -- **BREAKING** a bare `cloud` statement is meaningless: the *attributes* may be abstract, but the *values* are different for every provider.
95
+ - Anywhere you used to say `cloud`, say `ec2`: eg `ec2.flavor('t1.micro')` instead of `cloud.flavor('t1.micro')`.
96
+
97
+ * `chef_attributes` -- **BREAKING** replaced by `facet_role.override_attributes`, `facet_role.default_attributes` (or those methods on `cluster_role`.)
98
+
99
+ * `cluster_role_implication` -- **BREAKING** now called role_implications, brought in by default.
100
+
101
+ * `cluster.mounts_ephemeral_volumes` is now `cloud.mount_ephemerals`; it is not done by default.
102
+
103
+ ### Knife Changes
104
+
105
+ 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.
106
+
107
+ * `knife cluster kill` **only asks you once** whether to kill things -- there's no more `--really` flag.
108
+ * Standalone args now all properly have `--whatever` and `--no-whatever` forms.
109
+ * **BREAKING** The sync and kill commands both agree that `--chef` and `--cloud` are how to restrict their attention.
110
+
111
+
112
+ ### Cookbook-affecting changes
113
+
114
+ * 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[:ironfan][:facet]` and `node[:cluster_role]` (use `node[:facet_name]`), `node[:ironfan][:index]` and `node[:cluster_role_index]` (use `node[:facet_index]`) .
115
+ * Ironfan family of cookbooks were updated accordingly.
116
+
117
+ #### hadoop_cluster cookbook
118
+
119
+ * The bootstrap recipes are gone. They may come back, but for now the dance is:
120
+ - bring up the cluster ; by default the service state for all the daemons is [:disable, :stop].
121
+ - run the `/etc/hadoop/conf/bootstrap_hadoop_namenode.sh` to format your HDFS
122
+ - move the service state to '[:enable, :start]' and re-run chef client
123
+
124
+
125
+ #### Deprecated cookbooks
126
+
127
+ You must add `"#{ironfan_path}/deprecated-cookbooks"` to your cookbook_path in knife.rb if you would like to keep using
128
+
129
+ * `cluster_ebs_volumes` -- use `mountable_volumes` instead.
130
+
data/Gemfile ADDED
@@ -0,0 +1,26 @@
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
+ group :development do
9
+ gem 'bundler', "~> 1"
10
+ gem 'jeweler', "~> 1.6"
11
+ gem 'rspec', "~> 2.5"
12
+ gem 'yard', "~> 0.6"
13
+ gem 'configliere', "~> 0.4.8"
14
+ end
15
+
16
+ group :test do
17
+ gem 'spork', ">= 0.9.0", :platform => :mri
18
+ gem 'rcov', ">= 0.9.9", :platform => :ruby_18
19
+ gem 'simplecov', ">= 0.5", :platform => :ruby_19
20
+ gem 'watchr', "~> 0.7"
21
+ end
22
+
23
+ group :support do
24
+ gem 'pry'
25
+ gem 'grit'
26
+ end
data/LICENSE.md 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,328 @@
1
+ # ironfan
2
+
3
+ Infrastructure as code: describe and orchestrate whole clusters of cloud or virtual machines.
4
+
5
+ ## Walkthrough
6
+
7
+ Here's a very simple cluster:
8
+
9
+ ```ruby
10
+ Ironfan.cluster 'webapp_demo' do
11
+ cloud(:ec2) do
12
+ flavor 't1.micro'
13
+ end
14
+
15
+ role :base_role
16
+ role :chef_client
17
+ role :ssh
18
+
19
+ # The database server
20
+ facet :dbnode do
21
+ instances 1
22
+ role :mysql_server
23
+
24
+ cloud do
25
+ flavor 'm1.large'
26
+ backing 'ebs'
27
+ end
28
+ end
29
+
30
+ # A throwaway facet for development.
31
+ facet :webnode do
32
+ instances 2
33
+ role :nginx_server
34
+ role :awesome_webapp
35
+ end
36
+ end
37
+ ```
38
+
39
+ 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.
40
+
41
+ The webapp_demo 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.
42
+
43
+ The dbnode facet has one server, which will be named `webapp_demo-dbnode-0`; the webnode facet has two servers, `webapp_demo-webnode-0` and `webapp_demo-webnode-1`.
44
+
45
+ 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 `webapp_demo_webapp`.
46
+
47
+ 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.
48
+
49
+ ### Cluster-level tools
50
+
51
+
52
+ ```
53
+ $ knife cluster show webapp_demo
54
+
55
+ +--------------------+-------+------------+-------------+--------------+---------------+-----------------+----------+--------------+------------+------------+
56
+ | Name | Chef? | InstanceID | State | Public IP | Private IP | Created At | Flavor | Image | AZ | SSH Key |
57
+ +--------------------+-------+------------+-------------+--------------+---------------+-----------------+----------+--------------+------------+------------+
58
+ | webapp_demo-dbnode-0 | yes | i-43c60e20 | running | 107.22.6.104 | 10.88.112.201 | 20111029-204156 | t1.micro | ami-cef405a7 | us-east-1a | webapp_demo |
59
+ | webapp_demo-webnode-0 | yes | i-1233aef1 | running | 102.99.3.123 | 10.88.112.123 | 20111029-204156 | t1.micro | ami-cef405a7 | us-east-1a | webapp_demo |
60
+ | webapp_demo-webnode-1 | yes | i-0986423b | not running | | | | | | | |
61
+ +--------------------+-------+------------+-------------+--------------+---------------+-----------------+----------+--------------+------------+------------+
62
+
63
+
64
+ ```
65
+
66
+ The commands available are
67
+ * list -- lists known clusters
68
+ * show -- show the named servers
69
+ * launch -- launch server
70
+ * bootstrap
71
+ * sync
72
+ * ssh
73
+ * start/stop
74
+ * kill
75
+ * kick -- trigger a chef-client run on each named machine, tailing the logs until the run completes
76
+
77
+
78
+ ### Advanced clusters remain simple
79
+
80
+ 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.
81
+
82
+ ```ruby
83
+ Ironfan.cluster 'webserver_demo_2' do
84
+ cloud(:ec2) do
85
+ image_name "maverick"
86
+ flavor "t1.micro"
87
+ availability_zones ['us-east-1a']
88
+ end
89
+
90
+ # The database server
91
+ facet :dbnode do
92
+ instances 1
93
+ role :mysql_server
94
+ cloud do
95
+ flavor 'm1.large'
96
+ backing 'ebs'
97
+ end
98
+
99
+ volume(:data) do
100
+ size 20
101
+ keep true
102
+ device '/dev/sdi'
103
+ mount_point '/data'
104
+ snapshot_id 'snap-a10234f'
105
+ attachable :ebs
106
+ end
107
+ end
108
+
109
+ facet :webnode do
110
+ instances 6
111
+ cloud.availability_zones ['us-east-1a', 'us-east-1b']
112
+
113
+ role :nginx_server
114
+ role :awesome_webapp
115
+ role :elasticsearch_client
116
+
117
+ volume(:server_logs) do
118
+ size 5
119
+ keep true
120
+ device '/dev/sdi'
121
+ mount_point '/server_logs'
122
+ snapshot_id 'snap-d9c1edb1'
123
+ end
124
+ end
125
+
126
+ facet :esnode do
127
+ instances 1
128
+ role "elasticsearch_data_esnode"
129
+ role "elasticsearch_http_esnode"
130
+ cloud.flavor "m1.large"
131
+ end
132
+
133
+ facet :loadbalancer do
134
+ instances 1
135
+ role "haproxy"
136
+ cloud.flavor "m1.xlarge"
137
+ elastic_ip "128.69.69.23"
138
+ end
139
+
140
+ cluster_role.override_attributes({
141
+ :elasticsearch => {
142
+ :version => '0.17.8',
143
+ },
144
+ })
145
+ end
146
+ ```
147
+
148
+ 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 webapp_demo webnode` will note which machines are missing, and launch and configure them appropriately.
149
+
150
+ Ironfan 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.
151
+
152
+ 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):
153
+
154
+ * Synchronize to the chef server:
155
+ - create chef roles on the server for the cluster and each facet.
156
+ - apply role directives (eg the homebase's `default_attributes` declaration).
157
+ - create a node for each machine
158
+ - apply the runlist to each node
159
+ * Set up security isolation:
160
+ - uses a keypair (login ssh key) isolated to that cluster
161
+ - Recognizes the `ssh` role, and add a security group `ssh` that by default opens port 22.
162
+ - Recognize the `nfs_server` role, and adds security groups `nfs_server` and `nfs_client`
163
+ - 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. Ironfan's opinionated behavior is about more than saving you effort -- tying this behavior to the chef role means you can't screw it up.
164
+ * Launches the machines in parallel:
165
+ - using the image name and the availability zone, it determines the appropriate region, image ID, and other implied behavior.
166
+ - 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.
167
+ * Syncronizes to the cloud provider:
168
+ - Applies EC2 tags to the machine, making your console intelligible: ![AWS Console screenshot](https://github.com/infochimps-labs/ironfan/raw/version_3/notes/aws_console_screenshot.jpg)
169
+ - 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.
170
+ - Associates an elastic IP, if any, to the machine
171
+ * Bootstraps the machine using knife bootstrap
172
+
173
+ ---------------------------------------------------------------------------
174
+
175
+ ## Getting Started
176
+
177
+ 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.
178
+
179
+ ### Setup
180
+
181
+ ```ruby
182
+ bundle install
183
+ ```
184
+
185
+ ### Your first cluster
186
+
187
+ Let's create a cluster called 'demosimple'. It's, well, a simple demo cluster.
188
+
189
+ #### Create a simple demo cluster
190
+
191
+ Create a directory for your clusters; copy the demosimple cluster and its associated roles from ironfan:
192
+
193
+ ```ruby
194
+ mkdir -p $CHEF_REPO_DIR/clusters
195
+ cp ironfan/clusters/{defaults,demosimple}.rb ./clusters/
196
+ cp ironfan/roles/{big_package,nfs_*,ssh,base_role,chef_client}.rb ./roles/
197
+ ```
198
+
199
+ Lastly, add the `cookbooks`, `site-cookbooks`, and `meta-cookbooks` directories
200
+ from ironfan to the `cookbooks_path` in your knife.rb, and push everything
201
+ to the chef server. (see below for details).
202
+
203
+ #### knife cluster launch
204
+
205
+ Hooray! You're ready to launch a cluster:
206
+
207
+ ```ruby
208
+ knife cluster launch demosimple homebase --bootstrap
209
+ ```
210
+
211
+ It will kick off a node and then bootstrap it. You'll see it install a whole bunch of things. Yay.
212
+
213
+ __________________________________________________________________________
214
+
215
+ ## Philosophy
216
+
217
+ Some general principles of how we use chef.
218
+
219
+ * *Chef server is never the repository of truth* -- it only mirrors the truth.
220
+ - a file is tangible and immediate to access
221
+ * 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*.
222
+ - this means that everything is versioned, documented and exchangeable.
223
+ * *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.
224
+ - basically, the existence of anything that opens a port should be obvious when I look at the cluster file.
225
+ * *Roles define systems, clusters assemble systems into a machine*.
226
+ - 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.
227
+ - the existence of anything that opens a port _or_ runs as a service should be obvious when I look at the roles file.
228
+ * *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.
229
+ * It's nice when *machines are in full control of their destiny*.
230
+ - initial setup (elastic IP, attaching a drive) is often best enforced externally
231
+ - but machines should be ablt independently assert things like load balancer registration that that might change at any point in the lifetime.
232
+ * 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.
233
+
234
+ __________________________________________________________________________
235
+
236
+ ## Advanced Superpowers
237
+
238
+ #### Auto-vivifying machines (no bootstrap required!)
239
+
240
+ 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!
241
+
242
+ #### EBS Volumes
243
+
244
+ Define a `snapshot_id` for your volumes, and set `create_at_launch` true.
245
+
246
+ __________________________________________________________________________
247
+
248
+
249
+ ## Extended Installation Notes
250
+
251
+ #### Set up Knife on your local machine, and a Chef Server in the cloud
252
+
253
+ If you already have a working chef installation you can skip this section.
254
+
255
+ 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.
256
+
257
+ * [Launch Cloud Instances with Knife](http://wiki.opscode.com/display/chef/Launch+Cloud+Instances+with+Knife)
258
+ * [EC2 Bootstrap Fast Start Guide](http://wiki.opscode.com/display/chef/EC2+Bootstrap+Fast+Start+Guide)
259
+
260
+ #### Cloud setup
261
+
262
+ Next,
263
+
264
+ * sign up for an AWS account
265
+ * Follow the "Knife with AWS quickstart": on the opscode wiki.
266
+
267
+ 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-labs/ironfan/issues/28 or get in touch.
268
+
269
+ #### Knife setup
270
+
271
+ In your `.chef/knife.rb`, modify the cookbook path to include ironfan's `cookbooks`, `meta-cookbooks` and `site-cookbooks`, and to add settings for `ironfan_path`, `cluster_path` and `keypair_path`. Here's mine:
272
+
273
+ ```
274
+ current_dir = File.dirname(__FILE__)
275
+ organization = 'CHEF_ORGANIZATION'
276
+ username = 'CHEF_USERNAME'
277
+
278
+ # The full path to your ironfan installation
279
+ ironfan_path File.expand_path("#{current_dir}/../ironfan")
280
+ # The list of paths holding clusters
281
+ cluster_path [ File.expand_path("#{current_dir}/../clusters") ]
282
+ # The directory holding your cloud keypairs
283
+ keypair_path File.expand_path(current_dir)
284
+
285
+ log_level :info
286
+ log_location STDOUT
287
+ node_name username
288
+ client_key "#{keypair_path}/#{username}.pem"
289
+ validation_client_name "#{organization}-validator"
290
+ validation_key "#{keypair_path}/#{organization}-validator.pem"
291
+ chef_server_url "https://api.opscode.com/organizations/#{organization}"
292
+ cache_type 'BasicFile'
293
+ cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
294
+
295
+ # The first things have lowest priority (so, site-cookbooks gets to win)
296
+ cookbook_path [
297
+ "#{ironfan_path}/cookbooks", # std cookbooks from opscode/cookbooks
298
+ "#{ironfan_path}/meta-cookbooks", # coordinate services among cookbooks
299
+ "#{ironfan_path}/site-cookbooks", # infochimps' collection of cookbooks
300
+ "#{current_dir}/../cookbooks",
301
+ "#{current_dir}/../site-cookbooks", # your internal cookbooks
302
+ ]
303
+
304
+ # If you primarily use AWS cloud services:
305
+ knife[:ssh_address_attribute] = 'cloud.public_hostname'
306
+ knife[:ssh_user] = 'ubuntu'
307
+
308
+ # Configure bootstrapping
309
+ knife[:bootstrap_runs_chef_client] = true
310
+ bootstrap_chef_version "~> 0.10.0"
311
+
312
+ # AWS access credentials
313
+ knife[:aws_access_key_id] = "XXXXXXXXXXX"
314
+ knife[:aws_secret_access_key] = "XXXXXXXXXXXXX"
315
+ ```
316
+
317
+ #### Push to chef server
318
+
319
+ To send all the cookbooks and role to the chef server, visit your ironfan directory and run:
320
+
321
+ ```ruby
322
+ cd $CHEF_REPO_DIR
323
+ mkdir -p $CHEF_REPO_DIR/site-cookbooks
324
+ knife cookbook upload --all
325
+ for foo in roles/*.rb ; do knife role from file $foo & sleep 1 ; done
326
+ ```
327
+
328
+ You should see all the cookbooks defined in ironfan/cookbooks (ant, apt, ...) listed among those it uploads.