chef 0.10.0.beta.5 → 0.10.0.beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/chef/application.rb +13 -1
- data/lib/chef/application/client.rb +4 -2
- data/lib/chef/application/knife.rb +26 -2
- data/lib/chef/application/solo.rb +4 -3
- data/lib/chef/client.rb +2 -1
- data/lib/chef/cookbook_version.rb +2 -1
- data/lib/chef/knife.rb +129 -37
- data/lib/chef/knife/cookbook_metadata.rb +8 -3
- data/lib/chef/knife/cookbook_site_install.rb +3 -127
- data/lib/chef/knife/cookbook_site_vendor.rb +46 -0
- data/lib/chef/knife/cookbook_test.rb +13 -2
- data/lib/chef/knife/core/cookbook_scm_repo.rb +149 -0
- data/lib/chef/knife/core/generic_presenter.rb +184 -0
- data/lib/chef/knife/core/node_editor.rb +127 -0
- data/lib/chef/knife/core/node_presenter.rb +103 -0
- data/lib/chef/knife/core/object_loader.rb +75 -0
- data/lib/chef/knife/{subcommand_loader.rb → core/subcommand_loader.rb} +1 -1
- data/lib/chef/knife/core/text_formatter.rb +100 -0
- data/lib/chef/knife/{ui.rb → core/ui.rb} +53 -73
- data/lib/chef/knife/data_bag_from_file.rb +8 -2
- data/lib/chef/knife/environment_from_file.rb +14 -3
- data/lib/chef/knife/node_edit.rb +14 -105
- data/lib/chef/knife/node_from_file.rb +6 -1
- data/lib/chef/knife/node_show.rb +6 -0
- data/lib/chef/knife/role_from_file.rb +6 -1
- data/lib/chef/knife/search.rb +34 -19
- data/lib/chef/knife/status.rb +15 -1
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +1 -4
- data/lib/chef/mixin/shell_out.rb +1 -0
- data/lib/chef/node.rb +17 -5
- data/lib/chef/resource.rb +42 -19
- data/lib/chef/rest.rb +14 -6
- data/lib/chef/rest/auth_credentials.rb +1 -1
- data/lib/chef/rest/rest_request.rb +26 -1
- data/lib/chef/runner.rb +2 -9
- data/lib/chef/version.rb +1 -1
- metadata +11 -7
- data/lib/chef/knife/bootstrap/client-install.vbs +0 -80
- data/lib/chef/knife/bootstrap/windows-gems.erb +0 -34
- data/lib/chef/knife/windows_bootstrap.rb +0 -157
data/lib/chef/resource.rb
CHANGED
@@ -372,34 +372,57 @@ F
|
|
372
372
|
@not_if
|
373
373
|
end
|
374
374
|
|
375
|
+
def defined_at
|
376
|
+
if cookbook_name && recipe_name && source_line
|
377
|
+
"#{cookbook_name}::#{recipe_name} line #{source_line.split(':')[1]}"
|
378
|
+
elsif source_line
|
379
|
+
file, line_no = source_line.split(':')
|
380
|
+
"#{file} line #{line_no}"
|
381
|
+
else
|
382
|
+
"dynamically defined"
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
375
386
|
def run_action(action)
|
387
|
+
Chef::Log.info("Processing #{self} action #{action} (#{defined_at})")
|
388
|
+
|
376
389
|
# ensure that we don't leave @updated_by_last_action set to true
|
377
390
|
# on accident
|
378
391
|
updated_by_last_action(false)
|
379
392
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
Chef::
|
386
|
-
|
393
|
+
begin
|
394
|
+
# Check if this resource has an only_if block -- if it does,
|
395
|
+
# evaluate the only_if block and skip the resource if
|
396
|
+
# appropriate.
|
397
|
+
if only_if
|
398
|
+
unless Chef::Mixin::Command.only_if(only_if, only_if_args)
|
399
|
+
Chef::Log.debug("Skipping #{self} due to only_if")
|
400
|
+
return
|
401
|
+
end
|
387
402
|
end
|
388
|
-
end
|
389
403
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
404
|
+
# Check if this resource has a not_if block -- if it does,
|
405
|
+
# evaluate the not_if block and skip the resource if
|
406
|
+
# appropriate.
|
407
|
+
if not_if
|
408
|
+
unless Chef::Mixin::Command.not_if(not_if, not_if_args)
|
409
|
+
Chef::Log.debug("Skipping #{self} due to not_if")
|
410
|
+
return
|
411
|
+
end
|
397
412
|
end
|
398
|
-
end
|
399
413
|
|
400
|
-
|
401
|
-
|
402
|
-
|
414
|
+
provider = Chef::Platform.provider_for_resource(self)
|
415
|
+
provider.load_current_resource
|
416
|
+
provider.send("action_#{action}")
|
417
|
+
rescue => e
|
418
|
+
if ignore_failure
|
419
|
+
Chef::Log.error("#{self} (#{defined_at}) had an error: #{e.message}")
|
420
|
+
else
|
421
|
+
Chef::Log.error("#{self} (#{defined_at}) has had an error")
|
422
|
+
msg = e.message
|
423
|
+
raise e.exception("#{self} (#{defined_at}) had an error: #{e.message}")
|
424
|
+
end
|
425
|
+
end
|
403
426
|
end
|
404
427
|
|
405
428
|
def updated_by_last_action(true_or_false)
|
data/lib/chef/rest.rb
CHANGED
@@ -24,7 +24,6 @@ require 'net/https'
|
|
24
24
|
require 'uri'
|
25
25
|
require 'chef/json_compat'
|
26
26
|
require 'tempfile'
|
27
|
-
require 'chef/api_client'
|
28
27
|
require 'chef/rest/auth_credentials'
|
29
28
|
require 'chef/rest/rest_request'
|
30
29
|
require 'chef/monkey_patches/string'
|
@@ -64,6 +63,10 @@ class Chef
|
|
64
63
|
end
|
65
64
|
|
66
65
|
# Register the client
|
66
|
+
#--
|
67
|
+
# Requires you to load chef/api_client beforehand. explicit require is removed since
|
68
|
+
# most users of this class have no need for chef/api_client. This functionality
|
69
|
+
# should be moved anyway...
|
67
70
|
def register(name=Chef::Config[:node_name], destination=Chef::Config[:client_key])
|
68
71
|
if (File.exists?(destination) && !File.writable?(destination))
|
69
72
|
raise Chef::Exceptions::CannotWritePrivateKey, "I cannot write your private key to #{destination} - check permissions?"
|
@@ -229,7 +232,7 @@ class Chef
|
|
229
232
|
exception = Chef::JSONCompat.from_json(response.body)
|
230
233
|
msg = "HTTP Request Returned #{response.code} #{response.message}: "
|
231
234
|
msg << (exception["error"].respond_to?(:join) ? exception["error"].join(", ") : exception["error"].to_s)
|
232
|
-
Chef::Log.
|
235
|
+
Chef::Log.info(msg)
|
233
236
|
end
|
234
237
|
response.error!
|
235
238
|
end
|
@@ -284,6 +287,9 @@ class Chef
|
|
284
287
|
|
285
288
|
res = yield rest_request
|
286
289
|
|
290
|
+
rescue SocketError, Errno::ETIMEDOUT => e
|
291
|
+
e.message.replace "Error connecting to #{url} - #{e.message}"
|
292
|
+
raise e
|
287
293
|
rescue Errno::ECONNREFUSED
|
288
294
|
if http_retry_count - http_attempts + 1 > 0
|
289
295
|
Chef::Log.error("Connection refused connecting to #{url.host}:#{url.port} for #{rest_request.path}, retry #{http_attempts}/#{http_retry_count}")
|
@@ -298,11 +304,13 @@ class Chef
|
|
298
304
|
retry
|
299
305
|
end
|
300
306
|
raise Timeout::Error, "Timeout connecting to #{url.host}:#{url.port} for #{rest_request.path}, giving up"
|
301
|
-
rescue Net::
|
302
|
-
|
307
|
+
rescue Net::HTTPFatalError => e
|
308
|
+
case e.response
|
309
|
+
when Net::HTTPServiceUnavailable
|
303
310
|
if http_retry_count - http_attempts + 1 > 0
|
304
|
-
|
305
|
-
|
311
|
+
sleep_time = 1 + (2 ** http_attempts) + rand(2 ** http_attempts)
|
312
|
+
Chef::Log.error("Service Unavailable for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s")
|
313
|
+
sleep(sleep_time)
|
306
314
|
retry
|
307
315
|
end
|
308
316
|
end
|
@@ -58,7 +58,7 @@ class Chef
|
|
58
58
|
@raw_key = IO.read(key_file).strip
|
59
59
|
@key = OpenSSL::PKey::RSA.new(@raw_key)
|
60
60
|
rescue SystemCallError, IOError => e
|
61
|
-
Chef::Log.
|
61
|
+
Chef::Log.warn "Failed to read the private key #{key_file}: #{e.inspect}"
|
62
62
|
raise Chef::Exceptions::PrivateKeyMissing, "I cannot read #{key_file}, which you told me to use to sign requests!"
|
63
63
|
rescue OpenSSL::PKey::RSAError
|
64
64
|
msg = "The file #{key_file} does not contain a correctly formatted private key.\n"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
3
|
# Author:: Thom May (<thom@clearairturbulence.org>)
|
4
4
|
# Author:: Nuo Yan (<nuo@opscode.com>)
|
@@ -23,11 +23,35 @@
|
|
23
23
|
require 'uri'
|
24
24
|
require 'net/http'
|
25
25
|
require 'chef/rest/cookie_jar'
|
26
|
+
|
27
|
+
# To load faster, we only want ohai's version string.
|
28
|
+
# However, in ohai before 0.6.0, the version is defined
|
29
|
+
# in ohai, not ohai/version
|
30
|
+
begin
|
31
|
+
require 'ohai/version' #used in user agent string.
|
32
|
+
rescue LoadError
|
33
|
+
require 'ohai'
|
34
|
+
end
|
35
|
+
|
26
36
|
require 'chef/version'
|
27
37
|
|
28
38
|
class Chef
|
29
39
|
class REST
|
30
40
|
class RESTRequest
|
41
|
+
|
42
|
+
engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
|
43
|
+
|
44
|
+
UA_COMMON = "/#{::Chef::VERSION} (#{engine}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}; ohai-#{Ohai::VERSION}; #{RUBY_PLATFORM}; +http://opscode.com)"
|
45
|
+
DEFAULT_UA = "Chef Client" << UA_COMMON
|
46
|
+
|
47
|
+
def self.user_agent=(ua)
|
48
|
+
@user_agent = ua
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.user_agent
|
52
|
+
@user_agent ||= DEFAULT_UA
|
53
|
+
end
|
54
|
+
|
31
55
|
attr_reader :method, :url, :headers, :http_client, :http_request
|
32
56
|
|
33
57
|
def initialize(method, url, req_body, base_headers={})
|
@@ -181,6 +205,7 @@ class Chef
|
|
181
205
|
@http_request.body = request_body if (request_body && @http_request.request_body_permitted?)
|
182
206
|
# Optionally handle HTTP Basic Authentication
|
183
207
|
@http_request.basic_auth(url.user, url.password) if url.user
|
208
|
+
@http_request['User-Agent'] = self.class.user_agent
|
184
209
|
end
|
185
210
|
|
186
211
|
end
|
data/lib/chef/runner.rb
CHANGED
@@ -74,15 +74,8 @@ class Chef
|
|
74
74
|
|
75
75
|
# Execute each resource.
|
76
76
|
run_context.resource_collection.execute_each_resource do |resource|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# Execute each of this resource's actions.
|
81
|
-
Array(resource.action).each {|action| run_action(resource, action)}
|
82
|
-
rescue => e
|
83
|
-
Chef::Log.error("#{resource} (#{resource.source_line}) had an error:\n#{e}\n#{e.backtrace.join("\n")}")
|
84
|
-
raise e unless resource.ignore_failure
|
85
|
-
end
|
77
|
+
# Execute each of this resource's actions.
|
78
|
+
Array(resource.action).each {|action| run_action(resource, action) }
|
86
79
|
end
|
87
80
|
|
88
81
|
# Run all our :delayed actions
|
data/lib/chef/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 7
|
5
|
-
version: 0.10.0.beta.
|
5
|
+
version: 0.10.0.beta.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Adam Jacob
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-04 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -295,11 +295,9 @@ files:
|
|
295
295
|
- lib/chef/json_compat.rb
|
296
296
|
- lib/chef/knife/bootstrap/archlinux-gems.erb
|
297
297
|
- lib/chef/knife/bootstrap/centos5-gems.erb
|
298
|
-
- lib/chef/knife/bootstrap/client-install.vbs
|
299
298
|
- lib/chef/knife/bootstrap/fedora13-gems.erb
|
300
299
|
- lib/chef/knife/bootstrap/ubuntu10.04-apt.erb
|
301
300
|
- lib/chef/knife/bootstrap/ubuntu10.04-gems.erb
|
302
|
-
- lib/chef/knife/bootstrap/windows-gems.erb
|
303
301
|
- lib/chef/knife/bootstrap.rb
|
304
302
|
- lib/chef/knife/client_bulk_delete.rb
|
305
303
|
- lib/chef/knife/client_create.rb
|
@@ -325,8 +323,17 @@ files:
|
|
325
323
|
- lib/chef/knife/cookbook_site_share.rb
|
326
324
|
- lib/chef/knife/cookbook_site_show.rb
|
327
325
|
- lib/chef/knife/cookbook_site_unshare.rb
|
326
|
+
- lib/chef/knife/cookbook_site_vendor.rb
|
328
327
|
- lib/chef/knife/cookbook_test.rb
|
329
328
|
- lib/chef/knife/cookbook_upload.rb
|
329
|
+
- lib/chef/knife/core/cookbook_scm_repo.rb
|
330
|
+
- lib/chef/knife/core/generic_presenter.rb
|
331
|
+
- lib/chef/knife/core/node_editor.rb
|
332
|
+
- lib/chef/knife/core/node_presenter.rb
|
333
|
+
- lib/chef/knife/core/object_loader.rb
|
334
|
+
- lib/chef/knife/core/subcommand_loader.rb
|
335
|
+
- lib/chef/knife/core/text_formatter.rb
|
336
|
+
- lib/chef/knife/core/ui.rb
|
330
337
|
- lib/chef/knife/data_bag_create.rb
|
331
338
|
- lib/chef/knife/data_bag_delete.rb
|
332
339
|
- lib/chef/knife/data_bag_edit.rb
|
@@ -361,12 +368,9 @@ files:
|
|
361
368
|
- lib/chef/knife/search.rb
|
362
369
|
- lib/chef/knife/ssh.rb
|
363
370
|
- lib/chef/knife/status.rb
|
364
|
-
- lib/chef/knife/subcommand_loader.rb
|
365
371
|
- lib/chef/knife/tag_create.rb
|
366
372
|
- lib/chef/knife/tag_delete.rb
|
367
373
|
- lib/chef/knife/tag_list.rb
|
368
|
-
- lib/chef/knife/ui.rb
|
369
|
-
- lib/chef/knife/windows_bootstrap.rb
|
370
374
|
- lib/chef/knife.rb
|
371
375
|
- lib/chef/log.rb
|
372
376
|
- lib/chef/mash.rb
|
@@ -1,80 +0,0 @@
|
|
1
|
-
'
|
2
|
-
' Author:: Doug MacEachern <dougm@vmware.com>
|
3
|
-
' Copyright:: Copyright (c) 2010 VMware, Inc.
|
4
|
-
' License:: Apache License, Version 2.0
|
5
|
-
'
|
6
|
-
' Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
' you may not use this file except in compliance with the License.
|
8
|
-
' You may obtain a copy of the License at
|
9
|
-
'
|
10
|
-
' http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
'
|
12
|
-
' Unless required by applicable law or agreed to in writing, software
|
13
|
-
' distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
' See the License for the specific language governing permissions and
|
16
|
-
' limitations under the License.
|
17
|
-
'
|
18
|
-
' download & install ruby && install chef client gems
|
19
|
-
|
20
|
-
Exe = "rubyinstaller-1.8.7-p249-rc2.exe"
|
21
|
-
Url = "http://rubyforge.org/frs/download.php/69034/" & Exe
|
22
|
-
Dst = "C:\Ruby"
|
23
|
-
Proxy = ""
|
24
|
-
If WScript.Arguments.Count = 1 Then
|
25
|
-
Proxy = WScript.Arguments.Item(0)
|
26
|
-
WScript.Echo "Using HTTP proxy=" & Proxy
|
27
|
-
End If
|
28
|
-
|
29
|
-
Set Shell = CreateObject("WScript.Shell")
|
30
|
-
Set Fs = CreateObject("Scripting.FileSystemObject")
|
31
|
-
If Fs.FileExists(Exe) Then
|
32
|
-
WScript.Echo "Using existing " & Exe
|
33
|
-
Else
|
34
|
-
WScript.Echo "Downloading " & Url
|
35
|
-
Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
|
36
|
-
If Proxy <> "" Then
|
37
|
-
Http.setProxy 2, Proxy, ""
|
38
|
-
End If
|
39
|
-
Http.Open "GET", Url, False
|
40
|
-
Http.Send
|
41
|
-
Set BinaryStream = CreateObject("ADODB.Stream")
|
42
|
-
BinaryStream.Type = 1
|
43
|
-
BinaryStream.Open
|
44
|
-
BinaryStream.Write Http.ResponseBody
|
45
|
-
BinaryStream.SaveToFile Exe, 2
|
46
|
-
BinaryStream.Close
|
47
|
-
End If
|
48
|
-
|
49
|
-
Ruby = Dst & "\bin\ruby.exe"
|
50
|
-
|
51
|
-
If Fs.FileExists(Ruby) Then
|
52
|
-
WScript.Echo Dst & " exists"
|
53
|
-
Else
|
54
|
-
WScript.Echo "Installing " & Exe & " to " & Dst
|
55
|
-
Cmd = Exe & " /dir=" & Dst & " /verysilent /tasks=assocfiles,modpath"
|
56
|
-
WScript.Echo Cmd
|
57
|
-
Set Exec = Shell.Exec(Cmd)
|
58
|
-
Do Until Exec.StdOut.AtEndOfStream
|
59
|
-
Line = Exec.StdOut.ReadLine()
|
60
|
-
Wscript.Echo Line
|
61
|
-
Loop
|
62
|
-
End If
|
63
|
-
|
64
|
-
GemProxy = ""
|
65
|
-
If Proxy <> "" Then
|
66
|
-
GemProxy = " --http-proxy=http://" & Proxy
|
67
|
-
End If
|
68
|
-
|
69
|
-
Cmd = Ruby & " " & Dst & "\bin\gem install" & GemProxy & " --no-ri --no-rdoc chef ruby-wmi windows-pr win32-open3 rubyzip"
|
70
|
-
WScript.Echo Cmd
|
71
|
-
Set Exec = Shell.Exec(Cmd)
|
72
|
-
Do Until Exec.StdOut.AtEndOfStream
|
73
|
-
Line = Exec.StdOut.ReadLine()
|
74
|
-
Wscript.Echo Line
|
75
|
-
Loop
|
76
|
-
Do Until Exec.StdErr.AtEndOfStream
|
77
|
-
Line = Exec.StdErr.ReadLine()
|
78
|
-
Wscript.Echo Line
|
79
|
-
Loop
|
80
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
cscript /nologo client-install.vbs <%= @config[:proxy] %>
|
2
|
-
|
3
|
-
> c:/chef/etc/client.rb (
|
4
|
-
@echo.log_level :info
|
5
|
-
@echo.log_location STDOUT
|
6
|
-
@echo.chef_server_url "<%= Chef::Config[:chef_server_url] %>"
|
7
|
-
@echo.validation_client_name "<%= Chef::Config[:validation_client_name] %>"
|
8
|
-
@echo.client_key "c:/chef/etc/client.pem"
|
9
|
-
@echo.validation_key "c:/chef/etc/validation.pem"
|
10
|
-
@echo.checksum_path "c:/chef/var/checksums"
|
11
|
-
@echo.file_cache_path "c:/chef/var/cache"
|
12
|
-
@echo.file_backup_path "c:/chef/var/backup"
|
13
|
-
@echo.cache_options ^( {:path, "c:/chef/var/cache/checksums", :skip_expires, true} ^)
|
14
|
-
<% if Chef::Config[:http_proxy] != nil %>
|
15
|
-
@echo.http_proxy "<%= Chef::Config[:http_proxy] %>"
|
16
|
-
<% end %>
|
17
|
-
<% if Chef::Config[:https_proxy] != nil %>
|
18
|
-
@echo.https_proxy "<%= Chef::Config[:https_proxy] %>"
|
19
|
-
<% end %>
|
20
|
-
<% if Chef::Config[:no_proxy] != nil %>
|
21
|
-
@echo.no_proxy "<%= Chef::Config[:no_proxy] %>"
|
22
|
-
<% end %>
|
23
|
-
<% if @config[:chef_node_name] == nil %>
|
24
|
-
@echo.# Using default node name
|
25
|
-
<% else %>
|
26
|
-
@echo.node_name "<%= @config[:chef_node_name] %>"
|
27
|
-
<% end %>
|
28
|
-
)
|
29
|
-
|
30
|
-
> c:/chef/etc/first-boot.json (
|
31
|
-
@echo.<%= { "run_list" => @run_list }.to_json %>
|
32
|
-
)
|
33
|
-
|
34
|
-
c:/ruby/bin/ruby c:/ruby/bin/chef-client -c c:/chef/etc/client.rb -j c:/chef/etc/first-boot.json -l <%= Chef::Config[:log_level] %>"
|
@@ -1,157 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Doug MacEachern <dougm@vmware.com>
|
3
|
-
# Copyright:: Copyright (c) 2010 VMware, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'fileutils'
|
20
|
-
|
21
|
-
class Chef
|
22
|
-
class Knife
|
23
|
-
class WindowsBootstrap < Chef::Knife::Bootstrap
|
24
|
-
|
25
|
-
deps do
|
26
|
-
require 'chef/knife/bootstrap.rb'
|
27
|
-
end
|
28
|
-
|
29
|
-
banner "knife windows bootstrap FQDN [RUN LIST...] (options)"
|
30
|
-
|
31
|
-
option :user,
|
32
|
-
:short => "-x USERNAME",
|
33
|
-
:long => "--user USERNAME",
|
34
|
-
:description => "The Windows username"
|
35
|
-
|
36
|
-
option :password,
|
37
|
-
:short => "-P PASSWORD",
|
38
|
-
:long => "--password PASSWORD",
|
39
|
-
:description => "The Windows password"
|
40
|
-
|
41
|
-
option :chef_node_name,
|
42
|
-
:short => "-N NAME",
|
43
|
-
:long => "--node-name NAME",
|
44
|
-
:description => "The Chef node name for your new node"
|
45
|
-
|
46
|
-
option :distro,
|
47
|
-
:short => "-d DISTRO",
|
48
|
-
:long => "--distro DISTRO",
|
49
|
-
:description => "Bootstrap a distro using a template",
|
50
|
-
:default => "windows-gems"
|
51
|
-
|
52
|
-
option :template_file,
|
53
|
-
:long => "--template-file TEMPLATE",
|
54
|
-
:description => "Full path to location of template to use",
|
55
|
-
:default => false
|
56
|
-
|
57
|
-
option :run_list,
|
58
|
-
:short => "-r RUN_LIST",
|
59
|
-
:long => "--run-list RUN_LIST",
|
60
|
-
:description => "Comma separated list of roles/recipes to apply",
|
61
|
-
:proc => lambda { |o| o.split(",") },
|
62
|
-
:default => []
|
63
|
-
|
64
|
-
def is_mounted
|
65
|
-
@net_use ||= Chef::Util::Windows::NetUse.new(@admin_share)
|
66
|
-
begin
|
67
|
-
@net_use.get_info
|
68
|
-
return true
|
69
|
-
rescue
|
70
|
-
return false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def mount_admin_share
|
75
|
-
if @add_mount && !is_mounted
|
76
|
-
use = {
|
77
|
-
:remote => @admin_share, :local => '',
|
78
|
-
:username => config[:user], :password => config[:password]
|
79
|
-
}
|
80
|
-
@net_use.add(use)
|
81
|
-
if is_mounted
|
82
|
-
ui.info("Mounted #{@admin_share} for copying files")
|
83
|
-
else
|
84
|
-
ui.fatal("Failed to mount #{@admin_share}")
|
85
|
-
exit 1
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def unmount_admin_share
|
91
|
-
if @add_mount && is_mounted
|
92
|
-
Chef::Log.debug("Unmounting #{@admin_share}")
|
93
|
-
@net_use.delete
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def psexec(args)
|
98
|
-
cmd = ['psexec', @unc_path, "-h", "-w", 'c:\chef\tmp']
|
99
|
-
if config[:user]
|
100
|
-
cmd << "-u" << config[:user]
|
101
|
-
end
|
102
|
-
if config[:password]
|
103
|
-
cmd << "-p" << config[:password]
|
104
|
-
end
|
105
|
-
cmd << args
|
106
|
-
cmd = cmd.join(' ')
|
107
|
-
Chef::Log.debug("system #{cmd}")
|
108
|
-
system(cmd)
|
109
|
-
end
|
110
|
-
|
111
|
-
def run
|
112
|
-
require 'chef/util/windows/net_use'
|
113
|
-
|
114
|
-
if @name_args.first == nil
|
115
|
-
ui.error("Must pass a node name/ip to windows bootstrap")
|
116
|
-
exit 1
|
117
|
-
end
|
118
|
-
|
119
|
-
config[:server_name] = @name_args.first
|
120
|
-
if Chef::Config[:http_proxy]
|
121
|
-
uri = URI.parse(Chef::Config[:http_proxy])
|
122
|
-
config[:proxy] = "#{uri.host}:#{uri.port}"
|
123
|
-
end
|
124
|
-
|
125
|
-
@unc_path = "\\\\#{config[:server_name]}"
|
126
|
-
@admin_share = "#{@unc_path}\\c$"
|
127
|
-
path = "#{@admin_share}\\chef"
|
128
|
-
etc = "#{path}\\etc"
|
129
|
-
tmp = "#{path}\\tmp"
|
130
|
-
|
131
|
-
$stdout.sync = true
|
132
|
-
|
133
|
-
command = render_template(load_template(config[:bootstrap_template]))
|
134
|
-
|
135
|
-
ui.info("Bootstrapping Chef on #{config[:server_name]}")
|
136
|
-
|
137
|
-
@add_mount = config[:user] != nil && !is_mounted
|
138
|
-
mount_admin_share
|
139
|
-
|
140
|
-
begin
|
141
|
-
[etc, tmp, "#{path}\\log"].each do |dir|
|
142
|
-
unless File.exists?(dir)
|
143
|
-
Chef::Log.debug("mkdir_p #{dir}")
|
144
|
-
FileUtils.mkdir_p(dir)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
File.open("#{tmp}\\bootstrap.bat", 'w') {|f| f.write(command) }
|
148
|
-
FileUtils.cp(File.join(File.dirname(__FILE__), 'bootstrap', 'client-install.vbs'), tmp)
|
149
|
-
FileUtils.cp(Chef::Config[:validation_key], etc)
|
150
|
-
psexec("cmd.exe /c bootstrap.bat")
|
151
|
-
ensure
|
152
|
-
unmount_admin_share
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|