knife-windows 0.8.6.rc.0 → 0.8.6
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 +54 -48
- data/Gemfile +11 -11
- data/LICENSE +201 -201
- data/README.md +161 -161
- data/RELEASE_NOTES.md +21 -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 -311
- 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 +8 -18
- data/DOC_CHANGES.md +0 -23
data/knife-windows.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "knife-windows/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "knife-windows"
|
7
|
-
s.version = Knife::Windows::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Seth Chisamore"]
|
10
|
-
s.email = ["schisamo@opscode.com"]
|
11
|
-
s.license = "Apache-2.0"
|
12
|
-
s.homepage = "https://github.com/opscode/knife-windows"
|
13
|
-
s.summary = %q{Plugin that adds functionality to Chef's Knife CLI for configuring/interacting with nodes running Microsoft Windows}
|
14
|
-
s.description = s.summary
|
15
|
-
|
16
|
-
s.required_ruby_version = ">= 1.9.1"
|
17
|
-
s.add_dependency "winrm-s", "~> 0.3.
|
18
|
-
s.add_dependency "em-winrm", "~> 0.7"
|
19
|
-
|
20
|
-
s.add_development_dependency 'pry'
|
21
|
-
|
22
|
-
s.files = `git ls-files`.split("\n")
|
23
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
-
s.require_paths = ["lib"]
|
26
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "knife-windows/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "knife-windows"
|
7
|
+
s.version = Knife::Windows::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Seth Chisamore"]
|
10
|
+
s.email = ["schisamo@opscode.com"]
|
11
|
+
s.license = "Apache-2.0"
|
12
|
+
s.homepage = "https://github.com/opscode/knife-windows"
|
13
|
+
s.summary = %q{Plugin that adds functionality to Chef's Knife CLI for configuring/interacting with nodes running Microsoft Windows}
|
14
|
+
s.description = s.summary
|
15
|
+
|
16
|
+
s.required_ruby_version = ">= 1.9.1"
|
17
|
+
s.add_dependency "winrm-s", "~> 0.3.1"
|
18
|
+
s.add_dependency "em-winrm", "~> 0.7"
|
19
|
+
|
20
|
+
s.add_development_dependency 'pry'
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
end
|
@@ -1,227 +1,227 @@
|
|
1
|
-
@rem
|
2
|
-
@rem Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
@rem Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
-
@rem License:: Apache License, Version 2.0
|
5
|
-
@rem
|
6
|
-
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
@rem you may not use this file except in compliance with the License.
|
8
|
-
@rem You may obtain a copy of the License at
|
9
|
-
@rem
|
10
|
-
@rem http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
@rem
|
12
|
-
@rem Unless required by applicable law or agreed to in writing, software
|
13
|
-
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
@rem See the License for the specific language governing permissions and
|
16
|
-
@rem limitations under the License.
|
17
|
-
@rem
|
18
|
-
|
19
|
-
@rem Use delayed environment expansion so that ERRORLEVEL can be evaluated with the
|
20
|
-
@rem !ERRORLEVEL! syntax which evaluates at execution of the line of script, not when
|
21
|
-
@rem the line is read. See help for the /E switch from cmd.exe /? .
|
22
|
-
@setlocal ENABLEDELAYEDEXPANSION
|
23
|
-
|
24
|
-
<%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
|
25
|
-
|
26
|
-
@set BOOTSTRAP_DIRECTORY=<%= bootstrap_directory %>
|
27
|
-
@echo Checking for existing directory "%BOOTSTRAP_DIRECTORY%"...
|
28
|
-
@if NOT EXIST %BOOTSTRAP_DIRECTORY% (
|
29
|
-
@echo Existing directory not found, creating.
|
30
|
-
@mkdir %BOOTSTRAP_DIRECTORY%
|
31
|
-
) else (
|
32
|
-
@echo Existing directory found, skipping creation.
|
33
|
-
)
|
34
|
-
|
35
|
-
> <%= bootstrap_directory %>\wget.vbs (
|
36
|
-
<%= win_wget %>
|
37
|
-
)
|
38
|
-
|
39
|
-
> <%= bootstrap_directory %>\wget.ps1 (
|
40
|
-
<%= win_wget_ps %>
|
41
|
-
)
|
42
|
-
|
43
|
-
@rem Determine the version and the architecture
|
44
|
-
|
45
|
-
@FOR /F "usebackq tokens=1-8 delims=.[] " %%A IN (`ver`) DO (
|
46
|
-
@set WinMajor=%%D
|
47
|
-
@set WinMinor=%%E
|
48
|
-
@set WinBuild=%%F
|
49
|
-
)
|
50
|
-
|
51
|
-
@echo Detected Windows Version %WinMajor%.%WinMinor% Build %WinBuild%
|
52
|
-
|
53
|
-
@set LATEST_OS_VERSION_MAJOR=6
|
54
|
-
@set LATEST_OS_VERSION_MINOR=3
|
55
|
-
|
56
|
-
@if /i %WinMajor% GTR %LATEST_OS_VERSION_MAJOR% goto VersionUnknown
|
57
|
-
@if /i %WinMajor% EQU %LATEST_OS_VERSION_MAJOR% (
|
58
|
-
@if /i %WinMinor% GTR %LATEST_OS_VERSION_MINOR% goto VersionUnknown
|
59
|
-
)
|
60
|
-
|
61
|
-
goto Version%WinMajor%.%WinMinor%
|
62
|
-
|
63
|
-
:VersionUnknown
|
64
|
-
@rem If this is an unknown version of windows set the default
|
65
|
-
@set MACHINE_OS=2008r2
|
66
|
-
@echo Warning: Unknown version of Windows, assuming default of Windows %MACHINE_OS%
|
67
|
-
goto architecture_select
|
68
|
-
|
69
|
-
:Version6.0
|
70
|
-
@set MACHINE_OS=2008
|
71
|
-
goto architecture_select
|
72
|
-
|
73
|
-
:Version5.2
|
74
|
-
@set MACHINE_OS=2003r2
|
75
|
-
goto architecture_select
|
76
|
-
|
77
|
-
:Version6.1
|
78
|
-
@set MACHINE_OS=2008r2
|
79
|
-
goto architecture_select
|
80
|
-
|
81
|
-
:Version6.2
|
82
|
-
@set MACHINE_OS=2012
|
83
|
-
goto architecture_select
|
84
|
-
|
85
|
-
@rem Currently Windows Server 2012 R2 is treated as equivalent to Windows Server 2012
|
86
|
-
:Version6.3
|
87
|
-
goto Version6.2
|
88
|
-
|
89
|
-
:architecture_select
|
90
|
-
goto Architecture%PROCESSOR_ARCHITEW6432%
|
91
|
-
|
92
|
-
:Architecture
|
93
|
-
goto Architecture%PROCESSOR_ARCHITECTURE%
|
94
|
-
|
95
|
-
@rem If this is an unknown architecture set the default
|
96
|
-
@set MACHINE_ARCH=i686
|
97
|
-
goto install
|
98
|
-
|
99
|
-
:Architecturex86
|
100
|
-
@set MACHINE_ARCH=i686
|
101
|
-
goto install
|
102
|
-
|
103
|
-
:Architectureamd64
|
104
|
-
@set MACHINE_ARCH=x86_64
|
105
|
-
goto install
|
106
|
-
|
107
|
-
:install
|
108
|
-
@rem Install Chef using chef-client MSI installer
|
109
|
-
|
110
|
-
<% url="https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%" -%>
|
111
|
-
<% url += latest_current_windows_chef_version_query -%>
|
112
|
-
@set "REMOTE_SOURCE_MSI_URL=<%= url %>"
|
113
|
-
@set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
|
114
|
-
@set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
|
115
|
-
@set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
|
116
|
-
|
117
|
-
@rem Clear any pre-existing downloads
|
118
|
-
@echo Checking for existing downloaded package at "%LOCAL_DESTINATION_MSI_PATH%"
|
119
|
-
@if EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
|
120
|
-
@echo Found existing downloaded package, deleting.
|
121
|
-
@del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
|
122
|
-
@if ERRORLEVEL 1 (
|
123
|
-
echo Warning: Failed to delete pre-existing package with status code !ERRORLEVEL! > "&2"
|
124
|
-
)
|
125
|
-
) else (
|
126
|
-
echo No existing downloaded packages to delete.
|
127
|
-
)
|
128
|
-
|
129
|
-
@rem If there is somehow a name collision, remove pre-existing log
|
130
|
-
@if EXIST "%CHEF_CLIENT_MSI_LOG_PATH%" del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
|
131
|
-
|
132
|
-
@echo Attempting to download client package using cscript...
|
133
|
-
cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
|
134
|
-
|
135
|
-
@rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
|
136
|
-
@rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
|
137
|
-
@rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
|
138
|
-
@set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
|
139
|
-
@if ERRORLEVEL 1 (
|
140
|
-
@echo Failed cscript download with status code !DOWNLOAD_ERROR_STATUS! > "&2"
|
141
|
-
@if !DOWNLOAD_ERROR_STATUS!==0 set DOWNLOAD_ERROR_STATUS=2
|
142
|
-
) else (
|
143
|
-
@rem Sometimes the error level is not set even when the download failed,
|
144
|
-
@rem so check for the file to be sure it is there -- if it is not, we will retry
|
145
|
-
@if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
|
146
|
-
echo Failed download: download completed, but downloaded file not found > "&2"
|
147
|
-
set DOWNLOAD_ERROR_STATUS=2
|
148
|
-
) else (
|
149
|
-
echo Download via cscript succeeded.
|
150
|
-
)
|
151
|
-
)
|
152
|
-
|
153
|
-
@if NOT %DOWNLOAD_ERROR_STATUS%==0 (
|
154
|
-
@echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
|
155
|
-
@echo Warning: Retrying download with PowerShell if available...
|
156
|
-
|
157
|
-
@if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
|
158
|
-
|
159
|
-
@set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File <%= bootstrap_directory %>\wget.ps1 "%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%" "%LOCAL_DESTINATION_MSI_PATH%"
|
160
|
-
@echo !powershell_download!
|
161
|
-
@call !powershell_download!
|
162
|
-
@if NOT ERRORLEVEL 1 (
|
163
|
-
echo Download via PowerShell succeeded.
|
164
|
-
) else (
|
165
|
-
echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
|
166
|
-
echo Exiting without bootstrapping due to download failure. > "&2"
|
167
|
-
exit /b 1
|
168
|
-
)
|
169
|
-
)
|
170
|
-
|
171
|
-
@echo Installing downloaded client package...
|
172
|
-
|
173
|
-
<%= install_chef %>
|
174
|
-
|
175
|
-
@if ERRORLEVEL 1 (
|
176
|
-
echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
|
177
|
-
echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
|
178
|
-
) else (
|
179
|
-
@echo Installation completed successfully
|
180
|
-
del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
|
181
|
-
)
|
182
|
-
|
183
|
-
@endlocal
|
184
|
-
|
185
|
-
@echo off
|
186
|
-
echo Writing validation key...
|
187
|
-
|
188
|
-
> <%= bootstrap_directory %>\validation.pem (
|
189
|
-
<%= validation_key %>
|
190
|
-
)
|
191
|
-
|
192
|
-
echo Validation key written.
|
193
|
-
@echo on
|
194
|
-
|
195
|
-
<% if @config[:encrypted_data_bag_secret] -%>
|
196
|
-
> <%= bootstrap_directory %>\encrypted_data_bag_secret (
|
197
|
-
<%= encrypted_data_bag_secret %>
|
198
|
-
)
|
199
|
-
<% end -%>
|
200
|
-
|
201
|
-
<% unless trusted_certs.empty? -%>
|
202
|
-
mkdir <%= bootstrap_directory %>\trusted_certs
|
203
|
-
<%= trusted_certs %>
|
204
|
-
<% end -%>
|
205
|
-
|
206
|
-
<%# Generate Ohai Hints -%>
|
207
|
-
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
|
208
|
-
mkdir <%= bootstrap_directory %>\ohai\hints
|
209
|
-
|
210
|
-
<% @chef_config[:knife][:hints].each do |name, hash| -%>
|
211
|
-
> <%= bootstrap_directory %>\ohai\hints\<%= name %>.json (
|
212
|
-
<%= escape_and_echo(hash.to_json) %>
|
213
|
-
)
|
214
|
-
<% end -%>
|
215
|
-
<% end -%>
|
216
|
-
|
217
|
-
> <%= bootstrap_directory %>\client.rb (
|
218
|
-
<%= config_content %>
|
219
|
-
)
|
220
|
-
|
221
|
-
> <%= bootstrap_directory %>\first-boot.json (
|
222
|
-
<%= first_boot %>
|
223
|
-
)
|
224
|
-
|
225
|
-
@echo Starting chef to bootstrap the node...
|
226
|
-
<%= start_chef %>
|
227
|
-
|
1
|
+
@rem
|
2
|
+
@rem Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
@rem Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
+
@rem License:: Apache License, Version 2.0
|
5
|
+
@rem
|
6
|
+
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
@rem you may not use this file except in compliance with the License.
|
8
|
+
@rem You may obtain a copy of the License at
|
9
|
+
@rem
|
10
|
+
@rem http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
@rem
|
12
|
+
@rem Unless required by applicable law or agreed to in writing, software
|
13
|
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
@rem See the License for the specific language governing permissions and
|
16
|
+
@rem limitations under the License.
|
17
|
+
@rem
|
18
|
+
|
19
|
+
@rem Use delayed environment expansion so that ERRORLEVEL can be evaluated with the
|
20
|
+
@rem !ERRORLEVEL! syntax which evaluates at execution of the line of script, not when
|
21
|
+
@rem the line is read. See help for the /E switch from cmd.exe /? .
|
22
|
+
@setlocal ENABLEDELAYEDEXPANSION
|
23
|
+
|
24
|
+
<%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
|
25
|
+
|
26
|
+
@set BOOTSTRAP_DIRECTORY=<%= bootstrap_directory %>
|
27
|
+
@echo Checking for existing directory "%BOOTSTRAP_DIRECTORY%"...
|
28
|
+
@if NOT EXIST %BOOTSTRAP_DIRECTORY% (
|
29
|
+
@echo Existing directory not found, creating.
|
30
|
+
@mkdir %BOOTSTRAP_DIRECTORY%
|
31
|
+
) else (
|
32
|
+
@echo Existing directory found, skipping creation.
|
33
|
+
)
|
34
|
+
|
35
|
+
> <%= bootstrap_directory %>\wget.vbs (
|
36
|
+
<%= win_wget %>
|
37
|
+
)
|
38
|
+
|
39
|
+
> <%= bootstrap_directory %>\wget.ps1 (
|
40
|
+
<%= win_wget_ps %>
|
41
|
+
)
|
42
|
+
|
43
|
+
@rem Determine the version and the architecture
|
44
|
+
|
45
|
+
@FOR /F "usebackq tokens=1-8 delims=.[] " %%A IN (`ver`) DO (
|
46
|
+
@set WinMajor=%%D
|
47
|
+
@set WinMinor=%%E
|
48
|
+
@set WinBuild=%%F
|
49
|
+
)
|
50
|
+
|
51
|
+
@echo Detected Windows Version %WinMajor%.%WinMinor% Build %WinBuild%
|
52
|
+
|
53
|
+
@set LATEST_OS_VERSION_MAJOR=6
|
54
|
+
@set LATEST_OS_VERSION_MINOR=3
|
55
|
+
|
56
|
+
@if /i %WinMajor% GTR %LATEST_OS_VERSION_MAJOR% goto VersionUnknown
|
57
|
+
@if /i %WinMajor% EQU %LATEST_OS_VERSION_MAJOR% (
|
58
|
+
@if /i %WinMinor% GTR %LATEST_OS_VERSION_MINOR% goto VersionUnknown
|
59
|
+
)
|
60
|
+
|
61
|
+
goto Version%WinMajor%.%WinMinor%
|
62
|
+
|
63
|
+
:VersionUnknown
|
64
|
+
@rem If this is an unknown version of windows set the default
|
65
|
+
@set MACHINE_OS=2008r2
|
66
|
+
@echo Warning: Unknown version of Windows, assuming default of Windows %MACHINE_OS%
|
67
|
+
goto architecture_select
|
68
|
+
|
69
|
+
:Version6.0
|
70
|
+
@set MACHINE_OS=2008
|
71
|
+
goto architecture_select
|
72
|
+
|
73
|
+
:Version5.2
|
74
|
+
@set MACHINE_OS=2003r2
|
75
|
+
goto architecture_select
|
76
|
+
|
77
|
+
:Version6.1
|
78
|
+
@set MACHINE_OS=2008r2
|
79
|
+
goto architecture_select
|
80
|
+
|
81
|
+
:Version6.2
|
82
|
+
@set MACHINE_OS=2012
|
83
|
+
goto architecture_select
|
84
|
+
|
85
|
+
@rem Currently Windows Server 2012 R2 is treated as equivalent to Windows Server 2012
|
86
|
+
:Version6.3
|
87
|
+
goto Version6.2
|
88
|
+
|
89
|
+
:architecture_select
|
90
|
+
goto Architecture%PROCESSOR_ARCHITEW6432%
|
91
|
+
|
92
|
+
:Architecture
|
93
|
+
goto Architecture%PROCESSOR_ARCHITECTURE%
|
94
|
+
|
95
|
+
@rem If this is an unknown architecture set the default
|
96
|
+
@set MACHINE_ARCH=i686
|
97
|
+
goto install
|
98
|
+
|
99
|
+
:Architecturex86
|
100
|
+
@set MACHINE_ARCH=i686
|
101
|
+
goto install
|
102
|
+
|
103
|
+
:Architectureamd64
|
104
|
+
@set MACHINE_ARCH=x86_64
|
105
|
+
goto install
|
106
|
+
|
107
|
+
:install
|
108
|
+
@rem Install Chef using chef-client MSI installer
|
109
|
+
|
110
|
+
<% url="https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%" -%>
|
111
|
+
<% url += latest_current_windows_chef_version_query -%>
|
112
|
+
@set "REMOTE_SOURCE_MSI_URL=<%= url %>"
|
113
|
+
@set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
|
114
|
+
@set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
|
115
|
+
@set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
|
116
|
+
|
117
|
+
@rem Clear any pre-existing downloads
|
118
|
+
@echo Checking for existing downloaded package at "%LOCAL_DESTINATION_MSI_PATH%"
|
119
|
+
@if EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
|
120
|
+
@echo Found existing downloaded package, deleting.
|
121
|
+
@del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
|
122
|
+
@if ERRORLEVEL 1 (
|
123
|
+
echo Warning: Failed to delete pre-existing package with status code !ERRORLEVEL! > "&2"
|
124
|
+
)
|
125
|
+
) else (
|
126
|
+
echo No existing downloaded packages to delete.
|
127
|
+
)
|
128
|
+
|
129
|
+
@rem If there is somehow a name collision, remove pre-existing log
|
130
|
+
@if EXIST "%CHEF_CLIENT_MSI_LOG_PATH%" del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
|
131
|
+
|
132
|
+
@echo Attempting to download client package using cscript...
|
133
|
+
cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
|
134
|
+
|
135
|
+
@rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
|
136
|
+
@rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
|
137
|
+
@rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
|
138
|
+
@set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
|
139
|
+
@if ERRORLEVEL 1 (
|
140
|
+
@echo Failed cscript download with status code !DOWNLOAD_ERROR_STATUS! > "&2"
|
141
|
+
@if !DOWNLOAD_ERROR_STATUS!==0 set DOWNLOAD_ERROR_STATUS=2
|
142
|
+
) else (
|
143
|
+
@rem Sometimes the error level is not set even when the download failed,
|
144
|
+
@rem so check for the file to be sure it is there -- if it is not, we will retry
|
145
|
+
@if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
|
146
|
+
echo Failed download: download completed, but downloaded file not found > "&2"
|
147
|
+
set DOWNLOAD_ERROR_STATUS=2
|
148
|
+
) else (
|
149
|
+
echo Download via cscript succeeded.
|
150
|
+
)
|
151
|
+
)
|
152
|
+
|
153
|
+
@if NOT %DOWNLOAD_ERROR_STATUS%==0 (
|
154
|
+
@echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
|
155
|
+
@echo Warning: Retrying download with PowerShell if available...
|
156
|
+
|
157
|
+
@if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
|
158
|
+
|
159
|
+
@set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File <%= bootstrap_directory %>\wget.ps1 "%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%" "%LOCAL_DESTINATION_MSI_PATH%"
|
160
|
+
@echo !powershell_download!
|
161
|
+
@call !powershell_download!
|
162
|
+
@if NOT ERRORLEVEL 1 (
|
163
|
+
echo Download via PowerShell succeeded.
|
164
|
+
) else (
|
165
|
+
echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
|
166
|
+
echo Exiting without bootstrapping due to download failure. > "&2"
|
167
|
+
exit /b 1
|
168
|
+
)
|
169
|
+
)
|
170
|
+
|
171
|
+
@echo Installing downloaded client package...
|
172
|
+
|
173
|
+
<%= install_chef %>
|
174
|
+
|
175
|
+
@if ERRORLEVEL 1 (
|
176
|
+
echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
|
177
|
+
echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
|
178
|
+
) else (
|
179
|
+
@echo Installation completed successfully
|
180
|
+
del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
|
181
|
+
)
|
182
|
+
|
183
|
+
@endlocal
|
184
|
+
|
185
|
+
@echo off
|
186
|
+
echo Writing validation key...
|
187
|
+
|
188
|
+
> <%= bootstrap_directory %>\validation.pem (
|
189
|
+
<%= validation_key %>
|
190
|
+
)
|
191
|
+
|
192
|
+
echo Validation key written.
|
193
|
+
@echo on
|
194
|
+
|
195
|
+
<% if @config[:encrypted_data_bag_secret] -%>
|
196
|
+
> <%= bootstrap_directory %>\encrypted_data_bag_secret (
|
197
|
+
<%= encrypted_data_bag_secret %>
|
198
|
+
)
|
199
|
+
<% end -%>
|
200
|
+
|
201
|
+
<% unless trusted_certs.empty? -%>
|
202
|
+
mkdir <%= bootstrap_directory %>\trusted_certs
|
203
|
+
<%= trusted_certs %>
|
204
|
+
<% end -%>
|
205
|
+
|
206
|
+
<%# Generate Ohai Hints -%>
|
207
|
+
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
|
208
|
+
mkdir <%= bootstrap_directory %>\ohai\hints
|
209
|
+
|
210
|
+
<% @chef_config[:knife][:hints].each do |name, hash| -%>
|
211
|
+
> <%= bootstrap_directory %>\ohai\hints\<%= name %>.json (
|
212
|
+
<%= escape_and_echo(hash.to_json) %>
|
213
|
+
)
|
214
|
+
<% end -%>
|
215
|
+
<% end -%>
|
216
|
+
|
217
|
+
> <%= bootstrap_directory %>\client.rb (
|
218
|
+
<%= config_content %>
|
219
|
+
)
|
220
|
+
|
221
|
+
> <%= bootstrap_directory %>\first-boot.json (
|
222
|
+
<%= first_boot %>
|
223
|
+
)
|
224
|
+
|
225
|
+
@echo Starting chef to bootstrap the node...
|
226
|
+
<%= start_chef %>
|
227
|
+
|