knife-solo 0.3.0.pre2 → 0.3.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/CHANGELOG.md +70 -27
  2. data/README.rdoc +11 -6
  3. data/Rakefile +4 -2
  4. data/lib/chef/knife/bootstrap_solo.rb +40 -0
  5. data/lib/chef/knife/solo_bootstrap.rb +1 -1
  6. data/lib/chef/knife/solo_clean.rb +16 -4
  7. data/lib/chef/knife/solo_cook.rb +111 -36
  8. data/lib/chef/knife/solo_init.rb +14 -0
  9. data/lib/chef/knife/solo_prepare.rb +1 -1
  10. data/lib/knife-solo/bootstraps.rb +0 -18
  11. data/lib/knife-solo/bootstraps/darwin.rb +4 -16
  12. data/lib/knife-solo/bootstraps/linux.rb +36 -48
  13. data/lib/knife-solo/info.rb +1 -1
  14. data/lib/knife-solo/resources/knife.rb +4 -0
  15. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/.travis.yml +7 -0
  16. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/CHANGELOG +16 -0
  17. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/LICENSE +202 -0
  18. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/NOTICE +18 -0
  19. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/README.md +141 -0
  20. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/search.rb +72 -0
  21. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/search/overrides.rb +99 -0
  22. data/lib/{chef/knife/patches → knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/search}/parser.rb +1 -2
  23. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/vendor/chef/solr_query/lucene.treetop +150 -0
  24. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/vendor/chef/solr_query/lucene_nodes.rb +285 -0
  25. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/vendor/chef/solr_query/query_transform.rb +65 -0
  26. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/metadata.rb +11 -0
  27. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/recipes/default.rb +2 -0
  28. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/Gemfile +8 -0
  29. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/alpha.json +10 -0
  30. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/beta.json +10 -0
  31. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/without_json_class.json +7 -0
  32. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/jerry.json +8 -0
  33. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/lea.json +10 -0
  34. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/mike.json +13 -0
  35. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/tom.json +10 -0
  36. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_data_bags.rb +44 -0
  37. data/lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb +241 -0
  38. data/lib/knife-solo/resources/solo.rb.erb +10 -0
  39. data/lib/knife-solo/ssh_command.rb +4 -3
  40. data/lib/knife-solo/tools.rb +22 -0
  41. data/test/bootstraps_test.rb +4 -11
  42. data/test/integration/cases/encrypted_data_bag.rb +3 -0
  43. data/test/integration/cases/knife_bootstrap.rb +14 -0
  44. data/test/integration/debian6_bootstrap_test.rb +1 -1
  45. data/test/integration/{debian7_bootstrap_test.rb → debian7_knife_bootstrap_test.rb} +3 -3
  46. data/test/knife_bootstrap_test.rb +61 -0
  47. data/test/solo_cook_test.rb +78 -3
  48. data/test/support/integration_test.rb +8 -3
  49. data/test/tools_test.rb +82 -0
  50. metadata +63 -21
  51. data/lib/chef/knife/patches/search.rb +0 -110
  52. data/lib/knife-solo/config.rb +0 -39
  53. data/lib/knife-solo/resources/solo.rb +0 -6
  54. data/test/knife-solo/config_test.rb +0 -38
@@ -1,24 +1,67 @@
1
- # 0.3.0: _In progress_
1
+ # 0.3.0 / _In progress_
2
+
3
+ **NOTE**: This release includes breaking changes. See [upgrade instructions](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0) for more information.
2
4
 
3
5
  ## Changes and new features
4
6
 
5
- * Moved root path configuration into `knife[:solo_path]` and use $HOME/chef-solo by default (#197)
6
- * `--prerelease` option to allow pre-release versions of chef omnibus or rubygem to be installed (#205)
7
- * Prepare/bootstrap now installs the same version of Chef that the workstation is running (#186)
8
- * Switch `--omnibus-version` flag to `--bootstrap-version` (#185)
9
- * Support --override-runlist option (#204)
7
+ * Automatically add librarian to cookbook paths when syncing ([226])
8
+ * BREAKING: Generate solo.rb based on knife.rb settings ([199])
9
+ - `solo.rb` is not used and a warning is issued if it still found
10
+ - You have to specify the local cookbook etc. paths in `.chef/knife.rb`
11
+ * BREAKING: Set root path with `--provisioning-path` or `knife[:provisioning_path]` and use ~/chef-solo by default ([1], [86], [125], [128], [177], [197])
12
+ * BREAKING: Remove hard dependency on Librarian-Chef ([211])
13
+ - If you use Librarian integration you need to install the librarian-chef gem yourself
14
+ * Add `--solo` option and `knife[:solo]` configuration option to `knife bootstrap` ([207])
15
+ * `--prerelease` option to allow pre-release versions of chef omnibus or rubygem to be installed ([205])
16
+ * Prepare/bootstrap now installs the same version of Chef that the workstation is running ([186])
17
+ * Switch `--omnibus-version` flag to `--bootstrap-version` ([185])
18
+ * Support `--override-runlist` option ([204])
19
+ * Drop support for openSUSE 11
10
20
 
11
21
  ## Fixes
12
22
 
23
+ * Read protect the provision directory from the world ([1])
13
24
  * FreeBSD 9.1 support
14
- * Clear yum cache before installing rsync (#200)
25
+ * OS X (especially 10.8) support ([209], [210])
26
+ * Clear yum cache before installing rsync ([200])
27
+ * Make sure "ca-certificates" package is installed on Debian ([213])
28
+ * Ensure rsync is installed on openSUSE ([f43ba4])
29
+ * Clean up bootstrap classes ([213])
30
+ * Rsync dot files by default, exclude only VCS dirs ([d21756], [1d3485])
31
+ * Standardize messaging across commands [215]
32
+ * Librarian-Chef was not run by default when knife-solo was invoked from ruby ([221])
15
33
 
16
34
  ## Thanks to our contributors!
17
35
 
18
36
  * [David Kinzer][dkinzer]
19
37
  * [Naoya Ito][naoya]
20
-
21
- # 0.2.0: February 12, 2013
38
+ * [David Radcliffe][dwradcliffe]
39
+
40
+ [1]: https://github.com/matschaffer/knife-solo/issues/1
41
+ [86]: https://github.com/matschaffer/knife-solo/issues/86
42
+ [125]: https://github.com/matschaffer/knife-solo/issues/125
43
+ [128]: https://github.com/matschaffer/knife-solo/issues/128
44
+ [177]: https://github.com/matschaffer/knife-solo/issues/177
45
+ [185]: https://github.com/matschaffer/knife-solo/issues/185
46
+ [186]: https://github.com/matschaffer/knife-solo/issues/186
47
+ [197]: https://github.com/matschaffer/knife-solo/issues/197
48
+ [199]: https://github.com/matschaffer/knife-solo/issues/199
49
+ [200]: https://github.com/matschaffer/knife-solo/issues/200
50
+ [204]: https://github.com/matschaffer/knife-solo/issues/204
51
+ [205]: https://github.com/matschaffer/knife-solo/issues/205
52
+ [207]: https://github.com/matschaffer/knife-solo/issues/207
53
+ [209]: https://github.com/matschaffer/knife-solo/issues/209
54
+ [210]: https://github.com/matschaffer/knife-solo/issues/210
55
+ [211]: https://github.com/matschaffer/knife-solo/issues/211
56
+ [213]: https://github.com/matschaffer/knife-solo/issues/213
57
+ [215]: https://github.com/matschaffer/knife-solo/issues/215
58
+ [221]: https://github.com/matschaffer/knife-solo/issues/221
59
+ [226]: https://github.com/matschaffer/knife-solo/issues/221
60
+ [d21756]: https://github.com/matschaffer/knife-solo/commit/d21756
61
+ [1d3485]: https://github.com/matschaffer/knife-solo/commit/1d3485
62
+ [f43ba4]: https://github.com/matschaffer/knife-solo/commit/f43ba4
63
+
64
+ # 0.2.0 / 2013-02-12
22
65
 
23
66
  ## Changes and new features
24
67
 
@@ -36,7 +79,6 @@
36
79
  * Drop support for Debian 5.0 Lenny (#172)
37
80
  * Integration tests for Debian 6 and 7 (74c6ed1 - f299a6)
38
81
  * Travis tests for both Chef 10 and 11 (#183)
39
- * Remove solo.rb and transfer cookbooks to user-owned path (#1, #86, #125, #128, #177). See https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.2.0
40
82
 
41
83
  ## Fixes
42
84
 
@@ -55,7 +97,7 @@
55
97
  * [Shaun Dern][smdern]
56
98
  * [Mike Bain][TheAlphaTester]
57
99
 
58
- # 0.1.0: January 12, 2013
100
+ # 0.1.0 / 2013-01-12
59
101
 
60
102
  ## Changes and new features
61
103
 
@@ -80,7 +122,7 @@
80
122
  ## Documentation
81
123
 
82
124
  * Include documentation and tests in the gem (e01c23)
83
- * [Home page](http://matschaffer.github.com/knife-solo/)
125
+ * [Home page](http://matschaffer.github.io/knife-solo/)
84
126
  that reflects always the current release (#151)
85
127
 
86
128
  ## Thanks to our contributors!
@@ -92,7 +134,7 @@
92
134
  * [Hiten Parmar][hrp]
93
135
  * [Patrick Connolly][patcon]
94
136
 
95
- # 0.0.15: November 29th, 2012
137
+ # 0.0.15 / 2012-11-29
96
138
 
97
139
  * Support for non-x86 omnibus (#137)
98
140
  * Validate hostname in wash\_up (7a9115)
@@ -118,7 +160,7 @@
118
160
 
119
161
  And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of direct colaborators!
120
162
 
121
- # 0.0.14: September 21st, 2012
163
+ # 0.0.14 / 2012-09-21
122
164
 
123
165
  * Fix argument checks (#101)
124
166
  * Allow custom omnibus URLs (#99)
@@ -130,7 +172,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
130
172
  * [Ryan Walker][ryandub]
131
173
  * [Aaron Cruz][pferdefleisch]
132
174
 
133
- # 0.0.13: August 16th, 2012
175
+ # 0.0.13 / 2012-08-16
134
176
 
135
177
  * Less agressive in-kitchen check (36a14161a1c)
136
178
  * New curl/wget selection during omnibus install (#84)
@@ -143,7 +185,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
143
185
  * [Deepak Kannan][deepak]
144
186
  * [Florian Unglaub][funglaub]
145
187
 
146
- # 0.0.12: June 25th, 2012
188
+ # 0.0.12 / 2012-06-25
147
189
 
148
190
  * Better validation on CLI args (#68, #70)
149
191
  * Switch from wget to curl (#66)
@@ -156,7 +198,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
156
198
  * [Greg Fitzgerald][gregf]
157
199
  * [Deepak Kannan][deepak]
158
200
 
159
- # 0.0.11: June 16th, 2012
201
+ # 0.0.11 / 2012-06-16
160
202
 
161
203
  * Encrypted data bag support (#22)
162
204
  * Updated dependency version (#63, #64)
@@ -168,7 +210,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
168
210
  * [Hector Castro][hectcastro]
169
211
  * [Sean Porter][portertech]
170
212
 
171
- # 0.0.10: May 30th, 2012
213
+ # 0.0.10 / 2012-05-30
172
214
 
173
215
  * Include apache recipe during integration testing (#17)
174
216
  * Use omnibus installer on Ubuntu and RedHat (#40, #45, #58)
@@ -183,7 +225,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
183
225
  * [Justin Grevich][jgrevich]
184
226
  * [Ross Timson][rosstimson]
185
227
 
186
- # 0.0.9: May 13th, 2012
228
+ # 0.0.9 / 2012-05-13
187
229
 
188
230
  * Chef 0.10.10 compatibility (b0fa50e9)
189
231
  * Finished support and integration testing for remaining key OSes (Issues #2 and #15)
@@ -199,7 +241,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
199
241
  * [Tyler Rick][TylerRick]
200
242
  * [Motiejus Jakštys][Motiejus]
201
243
 
202
- # 0.0.8: February 10, 2012
244
+ # 0.0.8 / 2012-02-10
203
245
 
204
246
  * Add --startup-script which gets sourced before any command to setup env vars (e.g., ~/.bashrc) (d1489f94)
205
247
  * Use curl + rpm rather than rpm against direct URL for better proxy support (51ad9c51)
@@ -214,13 +256,13 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
214
256
  * [Jason Garber][jgarber]
215
257
  * [Greg Sterndale][gsterndale]
216
258
 
217
- # 0.0.7: Dec 9, 2011
259
+ # 0.0.7 / 2011-12-09
218
260
 
219
261
  * BUG #9: Fix intelligent sudo handling for OSes that don't have it
220
262
  * Move integration tests into proper test cases
221
263
  * CentOS 5.6 integration test
222
264
 
223
- # 0.0.6: Dec 8, 2011
265
+ # 0.0.6 / 2011-12-08
224
266
 
225
267
  * Support for Mac OS 10.5 and 10.6 (00921ebd1b93)
226
268
  * Parallel integration testing and SLES (167360d447..167360d447)
@@ -231,13 +273,13 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
231
273
  * [Sergio Rubio][rubiojr]
232
274
  * [Nat Lownes][natlownes]
233
275
 
234
- # 0.0.5: Oct 31, 2011
276
+ # 0.0.5 / 2011-10-31
235
277
 
236
278
  * Started on integration testing via EC2
237
279
  * Add openSuSE support. Installation via zypper. (64ff2edf42)
238
280
  * Upgraded Rubygems to 1.8.10 (8ac1f4d43a)
239
281
 
240
- # 0.0.4: Oct 7, 2011
282
+ # 0.0.4 / 2011-10-07
241
283
 
242
284
  * Chef 0.10.4 based databag and search method (a800880e6d)
243
285
  * Proper path for roles (b143ae290a)
@@ -247,7 +289,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
247
289
 
248
290
  * [John Dewey][retr0h]
249
291
 
250
- # 0.0.3: July 31, 2011
292
+ # 0.0.3 / 2011-07-31
251
293
 
252
294
  * Kitchen directory generation
253
295
  * Prepare tested on ubuntu
@@ -269,6 +311,8 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
269
311
  [btm]: https://github.com/btm
270
312
  [davidsch]: https://github.com/davidsch
271
313
  [deepak]: https://github.com/deepak
314
+ [dkinzer]: https://github.com/dkinzer
315
+ [dwradcliffe]: https://github.com/dwradcliffe
272
316
  [fnichol]: https://github.com/fnichol
273
317
  [funglaub]: https://github.com/funglaub
274
318
  [gregf]: https://github.com/gregf
@@ -277,6 +321,7 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
277
321
  [hrp]: https://github.com/hrp
278
322
  [jgarber]: https://github.com/jgarber
279
323
  [jgrevich]: https://github.com/jgrevich
324
+ [naoya]: https://github.com/naoya
280
325
  [natlownes]: https://github.com/natlownes
281
326
  [patatepartie]: https://github.com/patatepartie
282
327
  [patcon]: https://github.com/patcon
@@ -294,5 +339,3 @@ And a special thanks to [Teemu Matilainen][tmatilai] who is now on the list of d
294
339
  [tmatilai]: https://github.com/tmatilai
295
340
  [vjpr]: https://github.com/vjpr
296
341
  [zeph]: https://github.com/zeph
297
- [dkinzer]: https://github.com/dkinzer
298
- [naoya]: https://github.com/naoya
@@ -10,7 +10,7 @@ knife-solo adds a handful of commands that aim to make working with chef-solo as
10
10
 
11
11
  - <tt>knife solo cook</tt> uploads the current kitchen (Chef repo) to the target host and runs chef-solo on that host.
12
12
 
13
- - <tt>knife solo bootstrap</tt> combines the two previous ones (prepare and cook).
13
+ - <tt>knife solo bootstrap</tt> combines the two previous ones (prepare and cook). knife-solo also adds +--solo+ command line option and +knife[:solo]+ configuration parameter to <tt>knife bootstrap</tt> that can be used for triggering "knife solo bootstrap" instead of the normal template based chef-client bootstrap.
14
14
 
15
15
  - <tt>knife solo clean</tt> removes the uploaded kitchen from the target host.
16
16
 
@@ -35,12 +35,13 @@ The init command simply takes a name of the directory to store the kitchen struc
35
35
  Currently the directory structure looks like this, but could change as development continues.
36
36
 
37
37
  mychefrepo/
38
+ ├── .chef
39
+ │ └── knife.rb
38
40
  ├── cookbooks
39
41
  ├── data_bags
40
42
  ├── nodes
41
43
  ├── roles
42
- ├── site-cookbooks
43
- └── solo.rb
44
+ └── site-cookbooks
44
45
 
45
46
  === Prepare command
46
47
 
@@ -71,7 +72,7 @@ The cook command uploads the current kitchen to the server and runs chef-solo on
71
72
 
72
73
  This uploads all of your cookbooks in addition to a patch that allows you to use data_bags in a read-only fashion from the +data_bags+ folder.
73
74
 
74
- This also supports encrypted data bags. To use them, place your key in +data_bag_key+ in the root of your kitchen (or if you move it make sure to update +solo.rb+ to reflect the new path).
75
+ This also supports encrypted data bags. To use them, set the path to your key with +encrypted_data_bag_secret+ in .chef/knife.rb.
75
76
 
76
77
  The knife command for creating encrypted data bags doesn't work well without a Chef server, so use {this gist}[https://gist.github.com/2896172] as an example on how to create encrypted data bag items on your local file system.
77
78
 
@@ -83,6 +84,10 @@ The bootstrap command takes the same arguments and most of the options as prepar
83
84
 
84
85
  Under the hood it first calls +knife solo prepare+ and then +knife solo cook+ with the specified arguments and options.
85
86
 
87
+ ==== Integration with knife bootstrap
88
+
89
+ knife-solo also integrates with <tt>knife bootstrap</tt> by adding +--solo+ command line option and +knife[:solo]+ configuration parameter to it. When requested, "knife solo bootrap" is used instead of the normal template based chef-client bootstrap. This is especially useful with other knife plugins like {knife-ec2}[https://github.com/opscode/knife-ec2] that invoke "knife bootstrap" after creating an server instance. Even if these plugins do not have the "--solo" option, you can put <tt>knife[:solo] = true</tt> in knife.rb.
90
+
86
91
  === Clean command
87
92
 
88
93
  The clean command takes the same arguments like prepare and cook:
@@ -95,9 +100,9 @@ The clean command removes an uploaded kitchen completely from the target host. T
95
100
 
96
101
  The cook command will work on Windows node if you meet the following howto:
97
102
 
98
- ==== Init then tweak
103
+ ==== Init as normally
99
104
 
100
- - run <tt>knife solo init</tt> then edit solo.rb to use Windows path-naming (see https://gist.github.com/1773854)
105
+ - run <tt>knife solo init</tt>
101
106
 
102
107
  ==== Prepare the node manually
103
108
 
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), 'lib', 'knife-solo', 'info')
5
5
  MANIFEST_IGNORES = %w[
6
6
  .travis.yml
7
7
  .gitignore
8
+ .gitmodules
8
9
  Gemfile
9
10
  Gemfile.lock
10
11
  Manifest.txt
@@ -24,10 +25,11 @@ namespace :manifest do
24
25
 
25
26
  desc 'Updates Manifest.txt with a list of files from git'
26
27
  task :update do
27
- git_files = `git ls-files`.split("\n")
28
+ git_files = `git ls-files`.split("\n")
29
+ submodule_files = `git submodule foreach -q 'for f in $(git ls-files); do echo $path/$f; done'`.split("\n")
28
30
 
29
31
  File.open('Manifest.txt', 'w') do |f|
30
- f.puts((git_files - MANIFEST_IGNORES).join("\n"))
32
+ f.puts((git_files + submodule_files - MANIFEST_IGNORES).join("\n"))
31
33
  end
32
34
  end
33
35
  end
@@ -0,0 +1,40 @@
1
+ require 'chef/knife/bootstrap'
2
+
3
+ class Chef
4
+ class Knife
5
+ class Bootstrap
6
+
7
+ def self.load_deps
8
+ super
9
+ require 'chef/knife/solo_bootstrap'
10
+ require 'knife-solo/tools'
11
+ SoloBootstrap.load_deps
12
+ end
13
+
14
+ option :solo,
15
+ :long => '--[no-]solo',
16
+ :description => 'Bootstrap using knife-solo'
17
+
18
+ # Rename and override run method
19
+ alias_method :run_with_chef_client, :run
20
+
21
+ def run
22
+ if KnifeSolo::Tools.config_value(config, :solo)
23
+ run_with_knife_solo
24
+ else
25
+ run_with_chef_client
26
+ end
27
+ end
28
+
29
+ # Bootstraps Chef on the node using knife-solo
30
+ def run_with_knife_solo
31
+ validate_name_args!
32
+
33
+ bootstrap = SoloBootstrap.new
34
+ bootstrap.name_args = @name_args
35
+ bootstrap.config.merge! config
36
+ bootstrap.run
37
+ end
38
+ end
39
+ end
40
+ end
@@ -40,7 +40,7 @@ class Chef
40
40
  cmd = klass.new
41
41
  cmd.ui = ui
42
42
  cmd.name_args = @name_args
43
- cmd.config = config
43
+ cmd.config.merge! config
44
44
  cmd
45
45
  end
46
46
  end
@@ -1,24 +1,36 @@
1
1
  require 'chef/knife'
2
2
 
3
3
  require 'knife-solo/ssh_command'
4
- require 'knife-solo/config'
5
4
 
6
5
  class Chef
7
6
  class Knife
8
7
  class SoloClean < Knife
9
8
  include KnifeSolo::SshCommand
10
9
 
10
+ deps do
11
+ require 'knife-solo/tools'
12
+ KnifeSolo::SshCommand.load_deps
13
+ end
14
+
11
15
  banner "knife solo clean [USER@]HOSTNAME"
12
16
 
17
+ option :provisioning_path,
18
+ :long => '--provisioning-path path',
19
+ :description => 'Where to store kitchen data on the node'
20
+ # TODO de-duplicate this option with solo cook
21
+
13
22
  def run
14
- @solo_config = KnifeSolo::Config.new
15
23
  validate!
16
- run_command "rm -rf #{@solo_config.chef_path}"
24
+ run_command "rm -rf #{provisioning_path}"
17
25
  end
18
26
 
19
27
  def validate!
20
28
  validate_ssh_options!
21
- @solo_config.validate!
29
+ end
30
+
31
+ def provisioning_path
32
+ # TODO de-duplicate this method with solo cook
33
+ KnifeSolo::Tools.config_value(config, :provisioning_path, '~/chef-solo')
22
34
  end
23
35
  end
24
36
  end
@@ -4,7 +4,6 @@ require 'knife-solo'
4
4
  require 'knife-solo/ssh_command'
5
5
  require 'knife-solo/node_config_command'
6
6
  require 'knife-solo/tools'
7
- require 'knife-solo/config'
8
7
 
9
8
  class Chef
10
9
  class Knife
@@ -19,9 +18,9 @@ class Chef
19
18
 
20
19
  deps do
21
20
  require 'chef/cookbook/chefignore'
22
- require 'librarian/action'
23
- require 'librarian/chef'
21
+ require 'erubis'
24
22
  require 'pathname'
23
+ require 'tempfile'
25
24
  KnifeSolo::SshCommand.load_deps
26
25
  KnifeSolo::NodeConfigCommand.load_deps
27
26
  end
@@ -43,8 +42,7 @@ class Chef
43
42
 
44
43
  option :librarian,
45
44
  :long => '--no-librarian',
46
- :description => 'Skip librarian-chef install',
47
- :default => true
45
+ :description => 'Skip librarian-chef install'
48
46
 
49
47
  option :why_run,
50
48
  :short => '-W',
@@ -56,34 +54,76 @@ class Chef
56
54
  :long => '--override-runlist',
57
55
  :description => 'Replace current run list with specified items'
58
56
 
59
- def run
60
- @solo_config = KnifeSolo::Config.new
57
+ option :provisioning_path,
58
+ :long => '--provisioning-path path',
59
+ :description => 'Where to store kitchen data on the node'
61
60
 
61
+ def run
62
62
  time('Run') do
63
+
63
64
  if config[:skip_chef_check]
64
65
  ui.warn '`--skip-chef-check` is deprecated, please use `--no-chef-check`.'
65
66
  config[:chef_check] = false
66
67
  end
67
68
 
68
69
  validate!
70
+
71
+ ui.msg "Running Chef on #{host}..."
72
+
69
73
  check_chef_version if config[:chef_check]
70
74
  generate_node_config
71
- librarian_install if config[:librarian]
72
- rsync_kitchen
73
- add_patches
74
- add_solo_config unless using_custom_solorb?
75
+ librarian_install if config_value(:librarian, true)
76
+ sync_kitchen
77
+ generate_solorb
75
78
  cook unless config[:sync_only]
76
79
  end
77
80
  end
78
81
 
79
- def_delegators :@solo_config,
80
- :chef_path,
81
- :using_custom_solorb?,
82
- :patch_path
83
-
84
82
  def validate!
85
83
  validate_ssh_options!
86
- @solo_config.validate!
84
+
85
+ if File.exist? 'solo.rb'
86
+ ui.warn "solo.rb found, but since knife-solo v0.3.0 it is not used any more"
87
+ ui.warn "Please read the upgrade instructions: https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0"
88
+ end
89
+ end
90
+
91
+ def provisioning_path
92
+ # TODO ~ will likely break on cmd.exe based windows sessions
93
+ config_value(:provisioning_path, '~/chef-solo')
94
+ end
95
+
96
+ def sync_kitchen
97
+ ui.msg "Uploading the kitchen..."
98
+ run_portable_mkdir_p(provisioning_path, '0700')
99
+
100
+ cookbook_paths.each_with_index do |path, i|
101
+ upload_to_provision_path(path, "/cookbooks-#{i + 1}", 'cookbook_path')
102
+ end
103
+ upload_to_provision_path(nodes_path, 'nodes')
104
+ upload_to_provision_path(:role_path, 'roles')
105
+ upload_to_provision_path(:data_bag_path, 'data_bags')
106
+ upload_to_provision_path(:encrypted_data_bag_secret, 'data_bag_key')
107
+ end
108
+
109
+ def expanded_config_paths(key)
110
+ Array(Chef::Config[key]).map { |path| Pathname.new(path).expand_path }
111
+ end
112
+
113
+ def cookbook_paths
114
+ @cookbook_paths ||= expanded_config_paths(:cookbook_path) + [patch_cookbooks_path]
115
+ end
116
+
117
+ def add_cookbook_path(path)
118
+ cookbook_paths.unshift(path) unless cookbook_paths.include?(path)
119
+ end
120
+
121
+ def patch_cookbooks_path
122
+ KnifeSolo.resource('patch_cookbooks')
123
+ end
124
+
125
+ def nodes_path
126
+ 'nodes'
87
127
  end
88
128
 
89
129
  def chefignore
@@ -112,7 +152,7 @@ class Chef
112
152
  end
113
153
 
114
154
  def rsync_excludes
115
- (%w{revision-deploys tmp '.*'} + chefignore.ignores).uniq
155
+ (%w{revision-deploys tmp .git .hg .svn .bzr} + chefignore.ignores).uniq
116
156
  end
117
157
 
118
158
  def debug?
@@ -129,36 +169,70 @@ class Chef
129
169
  end
130
170
 
131
171
  def librarian_install
132
- return unless File.exist? 'Cheffile'
133
- Chef::Log.debug("Installing Librarian cookbooks")
134
- Librarian::Action::Resolve.new(librarian_env).run
135
- Librarian::Action::Install.new(librarian_env).run
172
+ if !File.exist? 'Cheffile'
173
+ Chef::Log.debug "Cheffile not found"
174
+ elsif !load_librarian
175
+ ui.warn "Librarian-Chef could not be loaded"
176
+ ui.warn "Please add the librarian-chef gem to your Gemfile or install it manually with `gem install librarian-chef`"
177
+ else
178
+ ui.msg "Installing Librarian cookbooks..."
179
+ Librarian::Action::Resolve.new(librarian_env).run
180
+ Librarian::Action::Install.new(librarian_env).run
181
+ add_cookbook_path librarian_env.install_path
182
+ end
183
+ end
184
+
185
+ def load_librarian
186
+ begin
187
+ require 'librarian/action'
188
+ require 'librarian/chef'
189
+ rescue LoadError
190
+ false
191
+ else
192
+ true
193
+ end
136
194
  end
137
195
 
138
196
  def librarian_env
139
197
  @librarian_env ||= Librarian::Chef::Environment.new
140
198
  end
141
199
 
142
- def rsync_kitchen
143
- time('Rsync kitchen') do
144
- rsync('./', chef_path, '--delete')
145
- end
200
+ def generate_solorb
201
+ ui.msg "Generating solo config..."
202
+ template = Erubis::Eruby.new(KnifeSolo.resource('solo.rb.erb').read)
203
+ write(template.result(binding), provisioning_path + '/solo.rb')
146
204
  end
147
205
 
148
- def add_patches
149
- run_portable_mkdir_p(patch_path)
150
- Dir[Pathname.new(__FILE__).dirname.join("patches", "*.rb").to_s].each do |patch|
151
- time(patch) do
152
- rsync(patch, patch_path)
153
- end
206
+ def upload(src, dest)
207
+ rsync(src, dest)
208
+ end
209
+
210
+ def upload_to_provision_path(src, dest, key_name = 'path')
211
+ if src.is_a? Symbol
212
+ key_name = src.to_s
213
+ src = Chef::Config[src]
214
+ end
215
+
216
+ if src.nil?
217
+ Chef::Log.debug "'#{key_name}' not set"
218
+ elsif !File.exist?(src)
219
+ ui.warn "Local #{key_name} '#{src}' does not exist"
220
+ else
221
+ upload("#{src}#{'/' if File.directory?(src)}", File.join(provisioning_path, dest))
154
222
  end
155
223
  end
156
224
 
157
- def add_solo_config
158
- rsync(KnifeSolo.resource('solo.rb'), chef_path)
225
+ # TODO probably can get Net::SSH to do this directly
226
+ def write(content, dest)
227
+ file = Tempfile.new(File.basename(dest))
228
+ file.write(content)
229
+ file.close
230
+ upload(file.path, dest)
231
+ ensure
232
+ file.unlink
159
233
  end
160
234
 
161
- def rsync(source_path, target_path, extra_opts = '')
235
+ def rsync(source_path, target_path, extra_opts = '--delete')
162
236
  cmd = %Q{rsync -rl #{rsync_permissions} --rsh="ssh #{ssh_args}" #{extra_opts} #{rsync_excludes.collect{ |ignore| "--exclude #{ignore} " }.join} #{adjust_rsync_path_on_client(source_path)} :#{adjust_rsync_path_on_node(target_path)}}
163
237
  ui.msg cmd if debug?
164
238
  system! cmd
@@ -178,7 +252,8 @@ class Chef
178
252
  end
179
253
 
180
254
  def cook
181
- cmd = "sudo chef-solo -c #{chef_path}/solo.rb -j #{chef_path}/#{node_config}"
255
+ ui.msg "Running Chef..."
256
+ cmd = "sudo chef-solo -c #{provisioning_path}/solo.rb -j #{provisioning_path}/#{node_config}"
182
257
  cmd << " -l debug" if debug?
183
258
  cmd << " -N #{config[:chef_node_name]}" if config[:chef_node_name]
184
259
  cmd << " -W" if config[:why_run]