knife-windows 0.8.5 → 0.8.6.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -4
- data/.travis.yml +6 -6
- data/CHANGELOG.md +48 -48
- data/DOC_CHANGES.md +23 -23
- data/Gemfile +11 -11
- data/LICENSE +201 -201
- data/README.md +161 -161
- data/RELEASE_NOTES.md +26 -26
- data/Rakefile +16 -16
- data/features/knife_help.feature +20 -20
- data/features/support/env.rb +5 -5
- data/knife-windows.gemspec +26 -26
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +227 -227
- data/lib/chef/knife/bootstrap_windows_base.rb +222 -222
- data/lib/chef/knife/bootstrap_windows_ssh.rb +93 -93
- data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -102
- data/lib/chef/knife/core/windows_bootstrap_context.rb +311 -307
- data/lib/chef/knife/windows_helper.rb +34 -34
- data/lib/chef/knife/winrm.rb +315 -315
- data/lib/chef/knife/winrm_base.rb +99 -99
- data/lib/knife-windows/path_helper.rb +157 -157
- data/lib/knife-windows/version.rb +6 -6
- data/spec/functional/bootstrap_download_spec.rb +122 -122
- data/spec/spec_helper.rb +61 -61
- data/spec/unit/knife/bootstrap_template_spec.rb +92 -92
- data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +106 -106
- data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +54 -54
- data/spec/unit/knife/winrm_spec.rb +219 -219
- metadata +28 -20
@@ -1,102 +1,102 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Opscode, 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 'chef/knife/bootstrap_windows_base'
|
20
|
-
require 'chef/knife/winrm'
|
21
|
-
require 'chef/knife/winrm_base'
|
22
|
-
require 'chef/knife/bootstrap'
|
23
|
-
|
24
|
-
class Chef
|
25
|
-
class Knife
|
26
|
-
class BootstrapWindowsWinrm < Bootstrap
|
27
|
-
|
28
|
-
include Chef::Knife::BootstrapWindowsBase
|
29
|
-
include Chef::Knife::WinrmBase
|
30
|
-
|
31
|
-
deps do
|
32
|
-
require 'chef/knife/core/windows_bootstrap_context'
|
33
|
-
require 'chef/json_compat'
|
34
|
-
require 'tempfile'
|
35
|
-
Chef::Knife::Winrm.load_deps
|
36
|
-
end
|
37
|
-
|
38
|
-
banner "knife bootstrap windows winrm FQDN (options)"
|
39
|
-
|
40
|
-
def run
|
41
|
-
bootstrap
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def run_command(command = '')
|
46
|
-
winrm = Chef::Knife::Winrm.new
|
47
|
-
winrm.name_args = [ server_name, command ]
|
48
|
-
winrm.config[:winrm_user] = locate_config_value(:winrm_user)
|
49
|
-
winrm.config[:winrm_password] = locate_config_value(:winrm_password)
|
50
|
-
winrm.config[:winrm_transport] = locate_config_value(:winrm_transport)
|
51
|
-
winrm.config[:kerberos_keytab_file] = Chef::Config[:knife][:kerberos_keytab_file] if Chef::Config[:knife][:kerberos_keytab_file]
|
52
|
-
winrm.config[:kerberos_realm] = Chef::Config[:knife][:kerberos_realm] if Chef::Config[:knife][:kerberos_realm]
|
53
|
-
winrm.config[:kerberos_service] = Chef::Config[:knife][:kerberos_service] if Chef::Config[:knife][:kerberos_service]
|
54
|
-
winrm.config[:ca_trust_file] = Chef::Config[:knife][:ca_trust_file] if Chef::Config[:knife][:ca_trust_file]
|
55
|
-
winrm.config[:manual] = true
|
56
|
-
winrm.config[:winrm_port] = locate_config_value(:winrm_port)
|
57
|
-
winrm.config[:suppress_auth_failure] = true
|
58
|
-
|
59
|
-
#If you turn off the return flag, then winrm.run won't atually check and
|
60
|
-
#return the error
|
61
|
-
#codes. Otherwise, it ignores the return value of the server call.
|
62
|
-
winrm.config[:returns] = "0"
|
63
|
-
winrm.run
|
64
|
-
end
|
65
|
-
|
66
|
-
protected
|
67
|
-
|
68
|
-
def wait_for_remote_response(wait_max_minutes)
|
69
|
-
wait_max_seconds = wait_max_minutes * 60
|
70
|
-
retry_interval_seconds = 10
|
71
|
-
retries_left = wait_max_seconds / retry_interval_seconds
|
72
|
-
print(ui.color("\nWaiting for remote response before bootstrap", :magenta))
|
73
|
-
wait_start_time = Time.now
|
74
|
-
begin
|
75
|
-
print(".")
|
76
|
-
# Return status of the command is non-zero, typically nil,
|
77
|
-
# for our simple echo command in cases where run_command
|
78
|
-
# swallows the exception, such as 401's. Treat such cases
|
79
|
-
# the same as the case where we encounter an exception.
|
80
|
-
status = run_command("echo . & echo Response received.")
|
81
|
-
raise RuntimeError, 'Command execution failed.' if status != 0
|
82
|
-
ui.info(ui.color("Remote node responded after #{elapsed_time_in_minutes(wait_start_time)} minutes.", :magenta))
|
83
|
-
return
|
84
|
-
rescue
|
85
|
-
retries_left -= 1
|
86
|
-
if retries_left <= 0 || (elapsed_time_in_minutes(wait_start_time) > wait_max_minutes)
|
87
|
-
ui.error("No response received from remote node after #{elapsed_time_in_minutes(wait_start_time)} minutes, giving up.")
|
88
|
-
raise
|
89
|
-
end
|
90
|
-
print '.'
|
91
|
-
sleep retry_interval_seconds
|
92
|
-
retry
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def elapsed_time_in_minutes(start_time)
|
97
|
-
((Time.now - start_time) / 60).round(2)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, 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 'chef/knife/bootstrap_windows_base'
|
20
|
+
require 'chef/knife/winrm'
|
21
|
+
require 'chef/knife/winrm_base'
|
22
|
+
require 'chef/knife/bootstrap'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Knife
|
26
|
+
class BootstrapWindowsWinrm < Bootstrap
|
27
|
+
|
28
|
+
include Chef::Knife::BootstrapWindowsBase
|
29
|
+
include Chef::Knife::WinrmBase
|
30
|
+
|
31
|
+
deps do
|
32
|
+
require 'chef/knife/core/windows_bootstrap_context'
|
33
|
+
require 'chef/json_compat'
|
34
|
+
require 'tempfile'
|
35
|
+
Chef::Knife::Winrm.load_deps
|
36
|
+
end
|
37
|
+
|
38
|
+
banner "knife bootstrap windows winrm FQDN (options)"
|
39
|
+
|
40
|
+
def run
|
41
|
+
bootstrap
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def run_command(command = '')
|
46
|
+
winrm = Chef::Knife::Winrm.new
|
47
|
+
winrm.name_args = [ server_name, command ]
|
48
|
+
winrm.config[:winrm_user] = locate_config_value(:winrm_user)
|
49
|
+
winrm.config[:winrm_password] = locate_config_value(:winrm_password)
|
50
|
+
winrm.config[:winrm_transport] = locate_config_value(:winrm_transport)
|
51
|
+
winrm.config[:kerberos_keytab_file] = Chef::Config[:knife][:kerberos_keytab_file] if Chef::Config[:knife][:kerberos_keytab_file]
|
52
|
+
winrm.config[:kerberos_realm] = Chef::Config[:knife][:kerberos_realm] if Chef::Config[:knife][:kerberos_realm]
|
53
|
+
winrm.config[:kerberos_service] = Chef::Config[:knife][:kerberos_service] if Chef::Config[:knife][:kerberos_service]
|
54
|
+
winrm.config[:ca_trust_file] = Chef::Config[:knife][:ca_trust_file] if Chef::Config[:knife][:ca_trust_file]
|
55
|
+
winrm.config[:manual] = true
|
56
|
+
winrm.config[:winrm_port] = locate_config_value(:winrm_port)
|
57
|
+
winrm.config[:suppress_auth_failure] = true
|
58
|
+
|
59
|
+
#If you turn off the return flag, then winrm.run won't atually check and
|
60
|
+
#return the error
|
61
|
+
#codes. Otherwise, it ignores the return value of the server call.
|
62
|
+
winrm.config[:returns] = "0"
|
63
|
+
winrm.run
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def wait_for_remote_response(wait_max_minutes)
|
69
|
+
wait_max_seconds = wait_max_minutes * 60
|
70
|
+
retry_interval_seconds = 10
|
71
|
+
retries_left = wait_max_seconds / retry_interval_seconds
|
72
|
+
print(ui.color("\nWaiting for remote response before bootstrap", :magenta))
|
73
|
+
wait_start_time = Time.now
|
74
|
+
begin
|
75
|
+
print(".")
|
76
|
+
# Return status of the command is non-zero, typically nil,
|
77
|
+
# for our simple echo command in cases where run_command
|
78
|
+
# swallows the exception, such as 401's. Treat such cases
|
79
|
+
# the same as the case where we encounter an exception.
|
80
|
+
status = run_command("echo . & echo Response received.")
|
81
|
+
raise RuntimeError, 'Command execution failed.' if status != 0
|
82
|
+
ui.info(ui.color("Remote node responded after #{elapsed_time_in_minutes(wait_start_time)} minutes.", :magenta))
|
83
|
+
return
|
84
|
+
rescue
|
85
|
+
retries_left -= 1
|
86
|
+
if retries_left <= 0 || (elapsed_time_in_minutes(wait_start_time) > wait_max_minutes)
|
87
|
+
ui.error("No response received from remote node after #{elapsed_time_in_minutes(wait_start_time)} minutes, giving up.")
|
88
|
+
raise
|
89
|
+
end
|
90
|
+
print '.'
|
91
|
+
sleep retry_interval_seconds
|
92
|
+
retry
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def elapsed_time_in_minutes(start_time)
|
97
|
+
((Time.now - start_time) / 60).round(2)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
@@ -1,307 +1,311 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Opscode, 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 'chef/knife/core/bootstrap_context'
|
20
|
-
|
21
|
-
# Chef::Util::PathHelper in Chef 11 is a bit juvenile still
|
22
|
-
require 'knife-windows/path_helper'
|
23
|
-
# require 'chef/util/path_helper'
|
24
|
-
|
25
|
-
class Chef
|
26
|
-
class Knife
|
27
|
-
module Core
|
28
|
-
# Instances of BootstrapContext are the context objects (i.e., +self+) for
|
29
|
-
# bootstrap templates. For backwards compatability, they +must+ set the
|
30
|
-
# following instance variables:
|
31
|
-
# * @config - a hash of knife's config values
|
32
|
-
# * @run_list - the run list for the node to boostrap
|
33
|
-
#
|
34
|
-
class WindowsBootstrapContext < BootstrapContext
|
35
|
-
PathHelper = ::Knife::Windows::PathHelper
|
36
|
-
|
37
|
-
def initialize(config, run_list, chef_config)
|
38
|
-
@config = config
|
39
|
-
@run_list = run_list
|
40
|
-
@chef_config = chef_config
|
41
|
-
super(config, run_list, chef_config)
|
42
|
-
end
|
43
|
-
|
44
|
-
def validation_key
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
def
|
53
|
-
@
|
54
|
-
end
|
55
|
-
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
when
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
if
|
108
|
-
client_rb <<
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
client_rb << %Q{no_proxy
|
116
|
-
end
|
117
|
-
|
118
|
-
if
|
119
|
-
client_rb << %Q{
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
client_rb << %Q{
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
proxy =
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
objADOStream
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
objADOStream.
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
$
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
def
|
231
|
-
|
232
|
-
end
|
233
|
-
|
234
|
-
def
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
def
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
command
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
@echo WARNING:
|
277
|
-
@echo WARNING:
|
278
|
-
@
|
279
|
-
|
280
|
-
@
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
@
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, 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 'chef/knife/core/bootstrap_context'
|
20
|
+
|
21
|
+
# Chef::Util::PathHelper in Chef 11 is a bit juvenile still
|
22
|
+
require 'knife-windows/path_helper'
|
23
|
+
# require 'chef/util/path_helper'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
module Core
|
28
|
+
# Instances of BootstrapContext are the context objects (i.e., +self+) for
|
29
|
+
# bootstrap templates. For backwards compatability, they +must+ set the
|
30
|
+
# following instance variables:
|
31
|
+
# * @config - a hash of knife's config values
|
32
|
+
# * @run_list - the run list for the node to boostrap
|
33
|
+
#
|
34
|
+
class WindowsBootstrapContext < BootstrapContext
|
35
|
+
PathHelper = ::Knife::Windows::PathHelper
|
36
|
+
|
37
|
+
def initialize(config, run_list, chef_config)
|
38
|
+
@config = config
|
39
|
+
@run_list = run_list
|
40
|
+
@chef_config = chef_config
|
41
|
+
super(config, run_list, chef_config)
|
42
|
+
end
|
43
|
+
|
44
|
+
def validation_key
|
45
|
+
if super
|
46
|
+
escape_and_echo(super)
|
47
|
+
else
|
48
|
+
raise 'Knife-Windows < 1.0 does not support validatorless bootstraps'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def encrypted_data_bag_secret
|
53
|
+
escape_and_echo(@config[:encrypted_data_bag_secret])
|
54
|
+
end
|
55
|
+
|
56
|
+
def trusted_certs
|
57
|
+
@trusted_certs ||= trusted_certs_content
|
58
|
+
end
|
59
|
+
|
60
|
+
def config_content
|
61
|
+
client_rb = <<-CONFIG
|
62
|
+
log_level :info
|
63
|
+
log_location STDOUT
|
64
|
+
|
65
|
+
chef_server_url "#{@chef_config[:chef_server_url]}"
|
66
|
+
validation_client_name "#{@chef_config[:validation_client_name]}"
|
67
|
+
client_key "c:/chef/client.pem"
|
68
|
+
validation_key "c:/chef/validation.pem"
|
69
|
+
|
70
|
+
file_cache_path "c:/chef/cache"
|
71
|
+
file_backup_path "c:/chef/backup"
|
72
|
+
cache_options ({:path => "c:/chef/cache/checksums", :skip_expires => true})
|
73
|
+
|
74
|
+
CONFIG
|
75
|
+
if @config[:chef_node_name]
|
76
|
+
client_rb << %Q{node_name "#{@config[:chef_node_name]}"\n}
|
77
|
+
else
|
78
|
+
client_rb << "# Using default node name (fqdn)\n"
|
79
|
+
end
|
80
|
+
|
81
|
+
# We configure :verify_api_cert only when it's overridden on the CLI
|
82
|
+
# or when specified in the knife config.
|
83
|
+
if !@config[:node_verify_api_cert].nil? || knife_config.has_key?(:verify_api_cert)
|
84
|
+
value = @config[:node_verify_api_cert].nil? ? knife_config[:verify_api_cert] : @config[:node_verify_api_cert]
|
85
|
+
client_rb << %Q{verify_api_cert #{value}\n}
|
86
|
+
end
|
87
|
+
|
88
|
+
# We configure :ssl_verify_mode only when it's overridden on the CLI
|
89
|
+
# or when specified in the knife config.
|
90
|
+
if @config[:node_ssl_verify_mode] || knife_config.has_key?(:ssl_verify_mode)
|
91
|
+
value = case @config[:node_ssl_verify_mode]
|
92
|
+
when "peer"
|
93
|
+
:verify_peer
|
94
|
+
when "none"
|
95
|
+
:verify_none
|
96
|
+
when nil
|
97
|
+
knife_config[:ssl_verify_mode]
|
98
|
+
else
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
|
102
|
+
if value
|
103
|
+
client_rb << %Q{ssl_verify_mode :#{value}\n}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if @config[:ssl_verify_mode]
|
108
|
+
client_rb << %Q{ssl_verify_mode :#{knife_config[:ssl_verify_mode]}\n}
|
109
|
+
end
|
110
|
+
|
111
|
+
if knife_config[:bootstrap_proxy]
|
112
|
+
client_rb << "\n"
|
113
|
+
client_rb << %Q{http_proxy "#{knife_config[:bootstrap_proxy]}"\n}
|
114
|
+
client_rb << %Q{https_proxy "#{knife_config[:bootstrap_proxy]}"\n}
|
115
|
+
client_rb << %Q{no_proxy "#{knife_config[:bootstrap_no_proxy]}"\n} if knife_config[:bootstrap_no_proxy]
|
116
|
+
end
|
117
|
+
|
118
|
+
if knife_config[:bootstrap_no_proxy]
|
119
|
+
client_rb << %Q{no_proxy "#{knife_config[:bootstrap_no_proxy]}"\n}
|
120
|
+
end
|
121
|
+
|
122
|
+
if @config[:encrypted_data_bag_secret]
|
123
|
+
client_rb << %Q{encrypted_data_bag_secret "c:/chef/encrypted_data_bag_secret"\n}
|
124
|
+
end
|
125
|
+
|
126
|
+
unless trusted_certs.empty?
|
127
|
+
client_rb << %Q{trusted_certs_dir "C:/chef/trusted_certs"\n}
|
128
|
+
end
|
129
|
+
|
130
|
+
escape_and_echo(client_rb)
|
131
|
+
end
|
132
|
+
|
133
|
+
def start_chef
|
134
|
+
start_chef = "SET \"PATH=%PATH%;C:\\ruby\\bin;C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin\"\n"
|
135
|
+
start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json -E #{bootstrap_environment}\n"
|
136
|
+
end
|
137
|
+
|
138
|
+
def latest_current_windows_chef_version_query
|
139
|
+
installer_version_string = nil
|
140
|
+
if @config[:prerelease]
|
141
|
+
installer_version_string = "&prerelease=true"
|
142
|
+
else
|
143
|
+
chef_version_string = if knife_config[:bootstrap_version]
|
144
|
+
knife_config[:bootstrap_version]
|
145
|
+
else
|
146
|
+
Chef::VERSION.split(".").first
|
147
|
+
end
|
148
|
+
|
149
|
+
installer_version_string = "&v=#{chef_version_string}"
|
150
|
+
|
151
|
+
# If bootstrapping a pre-release version add the prerelease query string
|
152
|
+
if chef_version_string.split(".").length > 3
|
153
|
+
installer_version_string << "&prerelease=true"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
installer_version_string
|
158
|
+
end
|
159
|
+
|
160
|
+
def win_wget
|
161
|
+
win_wget = <<-WGET
|
162
|
+
url = WScript.Arguments.Named("url")
|
163
|
+
path = WScript.Arguments.Named("path")
|
164
|
+
proxy = null
|
165
|
+
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
|
166
|
+
Set wshShell = CreateObject( "WScript.Shell" )
|
167
|
+
Set objUserVariables = wshShell.Environment("USER")
|
168
|
+
|
169
|
+
rem http proxy is optional
|
170
|
+
rem attempt to read from HTTP_PROXY env var first
|
171
|
+
On Error Resume Next
|
172
|
+
|
173
|
+
If NOT (objUserVariables("HTTP_PROXY") = "") Then
|
174
|
+
proxy = objUserVariables("HTTP_PROXY")
|
175
|
+
|
176
|
+
rem fall back to named arg
|
177
|
+
ElseIf NOT (WScript.Arguments.Named("proxy") = "") Then
|
178
|
+
proxy = WScript.Arguments.Named("proxy")
|
179
|
+
End If
|
180
|
+
|
181
|
+
If NOT isNull(proxy) Then
|
182
|
+
rem setProxy method is only available on ServerXMLHTTP 6.0+
|
183
|
+
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
|
184
|
+
objXMLHTTP.setProxy 2, proxy
|
185
|
+
End If
|
186
|
+
|
187
|
+
On Error Goto 0
|
188
|
+
|
189
|
+
objXMLHTTP.open "GET", url, false
|
190
|
+
objXMLHTTP.send()
|
191
|
+
If objXMLHTTP.Status = 200 Then
|
192
|
+
Set objADOStream = CreateObject("ADODB.Stream")
|
193
|
+
objADOStream.Open
|
194
|
+
objADOStream.Type = 1
|
195
|
+
objADOStream.Write objXMLHTTP.ResponseBody
|
196
|
+
objADOStream.Position = 0
|
197
|
+
Set objFSO = Createobject("Scripting.FileSystemObject")
|
198
|
+
If objFSO.Fileexists(path) Then objFSO.DeleteFile path
|
199
|
+
Set objFSO = Nothing
|
200
|
+
objADOStream.SaveToFile path
|
201
|
+
objADOStream.Close
|
202
|
+
Set objADOStream = Nothing
|
203
|
+
End if
|
204
|
+
Set objXMLHTTP = Nothing
|
205
|
+
WGET
|
206
|
+
escape_and_echo(win_wget)
|
207
|
+
end
|
208
|
+
|
209
|
+
def win_wget_ps
|
210
|
+
win_wget_ps = <<-WGET_PS
|
211
|
+
param(
|
212
|
+
[String] $remoteUrl,
|
213
|
+
[String] $localPath
|
214
|
+
)
|
215
|
+
|
216
|
+
$webClient = new-object System.Net.WebClient;
|
217
|
+
|
218
|
+
$webClient.DownloadFile($remoteUrl, $localPath);
|
219
|
+
WGET_PS
|
220
|
+
|
221
|
+
escape_and_echo(win_wget_ps)
|
222
|
+
end
|
223
|
+
|
224
|
+
def install_chef
|
225
|
+
# The normal install command uses regular double quotes in
|
226
|
+
# the install command, so request such a string from install_command
|
227
|
+
install_chef = install_command('"') + "\n" + fallback_install_task_command
|
228
|
+
end
|
229
|
+
|
230
|
+
def bootstrap_directory
|
231
|
+
bootstrap_directory = "C:\\chef"
|
232
|
+
end
|
233
|
+
|
234
|
+
def local_download_path
|
235
|
+
local_download_path = "%TEMP%\\chef-client-latest.msi"
|
236
|
+
end
|
237
|
+
|
238
|
+
def first_boot
|
239
|
+
first_boot_attributes_and_run_list = (@config[:first_boot_attributes] || {}).merge(:run_list => @run_list)
|
240
|
+
escape_and_echo(first_boot_attributes_and_run_list.to_json)
|
241
|
+
end
|
242
|
+
|
243
|
+
# escape WIN BATCH special chars
|
244
|
+
# and prefixes each line with an
|
245
|
+
# echo
|
246
|
+
def escape_and_echo(file_contents)
|
247
|
+
file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
|
248
|
+
end
|
249
|
+
|
250
|
+
private
|
251
|
+
|
252
|
+
def install_command(executor_quote)
|
253
|
+
"msiexec /qn /log #{executor_quote}%CHEF_CLIENT_MSI_LOG_PATH%#{executor_quote} /i #{executor_quote}%LOCAL_DESTINATION_MSI_PATH%#{executor_quote}"
|
254
|
+
end
|
255
|
+
|
256
|
+
def trusted_certs_content
|
257
|
+
content = ""
|
258
|
+
if @chef_config[:trusted_certs_dir]
|
259
|
+
Dir.glob(File.join(PathHelper.escape_glob(@chef_config[:trusted_certs_dir]), "*.{crt,pem}")).each do |cert|
|
260
|
+
content << "> #{bootstrap_directory}/trusted_certs/#{File.basename(cert)} (\n" +
|
261
|
+
escape_and_echo(IO.read(File.expand_path(cert))) + "\n)\n"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
content
|
265
|
+
end
|
266
|
+
|
267
|
+
def fallback_install_task_command
|
268
|
+
# This command will be executed by schtasks.exe in the batch
|
269
|
+
# code below. To handle tasks that contain arguments that
|
270
|
+
# need to be double quoted, schtasks allows the use of single
|
271
|
+
# quotes that will later be converted to double quotes
|
272
|
+
command = install_command('\'')
|
273
|
+
<<-EOH
|
274
|
+
@set MSIERRORCODE=!ERRORLEVEL!
|
275
|
+
@if ERRORLEVEL 1 (
|
276
|
+
@echo WARNING: Failed to install Chef Client MSI package in remote context with status code !MSIERRORCODE!.
|
277
|
+
@echo WARNING: This may be due to a defect in operating system update KB2918614: http://support.microsoft.com/kb/2918614
|
278
|
+
@set OLDLOGLOCATION="%CHEF_CLIENT_MSI_LOG_PATH%-fail.log"
|
279
|
+
@move "%CHEF_CLIENT_MSI_LOG_PATH%" "!OLDLOGLOCATION!" > NUL
|
280
|
+
@echo WARNING: Saving installation log of failure at !OLDLOGLOCATION!
|
281
|
+
@echo WARNING: Retrying installation with local context...
|
282
|
+
@schtasks /create /f /sc once /st 00:00:00 /tn chefclientbootstraptask /ru SYSTEM /rl HIGHEST /tr \"cmd /c #{command} & sleep 2 & waitfor /s %computername% /si chefclientinstalldone\"
|
283
|
+
|
284
|
+
@if ERRORLEVEL 1 (
|
285
|
+
@echo ERROR: Failed to create Chef Client installation scheduled task with status code !ERRORLEVEL! > "&2"
|
286
|
+
) else (
|
287
|
+
@echo Successfully created scheduled task to install Chef Client.
|
288
|
+
@schtasks /run /tn chefclientbootstraptask
|
289
|
+
@if ERRORLEVEL 1 (
|
290
|
+
@echo ERROR: Failed to execut Chef Client installation scheduled task with status code !ERRORLEVEL!. > "&2"
|
291
|
+
) else (
|
292
|
+
@echo Successfully started Chef Client installation scheduled task.
|
293
|
+
@echo Waiting for installation to complete -- this may take a few minutes...
|
294
|
+
waitfor chefclientinstalldone /t 600
|
295
|
+
if ERRORLEVEL 1 (
|
296
|
+
@echo ERROR: Timed out waiting for Chef Client package to install
|
297
|
+
) else (
|
298
|
+
@echo Finished waiting for Chef Client package to install.
|
299
|
+
)
|
300
|
+
@schtasks /delete /f /tn chefclientbootstraptask > NUL
|
301
|
+
)
|
302
|
+
)
|
303
|
+
) else (
|
304
|
+
@echo Successfully installed Chef Client package.
|
305
|
+
)
|
306
|
+
EOH
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|