knife-windows 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +26 -26
  3. data/CHANGELOG.md +139 -135
  4. data/DOC_CHANGES.md +22 -22
  5. data/Gemfile +13 -13
  6. data/README.md +404 -404
  7. data/RELEASE_NOTES.md +9 -9
  8. data/appveyor.yml +39 -39
  9. data/ci.gemfile +16 -16
  10. data/knife-windows.gemspec +26 -26
  11. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +246 -246
  12. data/lib/chef/knife/bootstrap_windows_base.rb +443 -443
  13. data/lib/chef/knife/bootstrap_windows_ssh.rb +116 -116
  14. data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -102
  15. data/lib/chef/knife/core/windows_bootstrap_context.rb +378 -378
  16. data/lib/chef/knife/knife_windows_base.rb +33 -33
  17. data/lib/chef/knife/windows_cert_generate.rb +155 -155
  18. data/lib/chef/knife/windows_cert_install.rb +68 -68
  19. data/lib/chef/knife/windows_helper.rb +36 -36
  20. data/lib/chef/knife/windows_listener_create.rb +107 -107
  21. data/lib/chef/knife/winrm.rb +122 -122
  22. data/lib/chef/knife/winrm_base.rb +128 -128
  23. data/lib/chef/knife/winrm_knife_base.rb +307 -307
  24. data/lib/chef/knife/winrm_session.rb +98 -98
  25. data/lib/chef/knife/winrm_shared_options.rb +47 -47
  26. data/lib/chef/knife/wsman_endpoint.rb +44 -44
  27. data/lib/chef/knife/wsman_test.rb +118 -118
  28. data/lib/knife-windows/path_helper.rb +242 -234
  29. data/lib/knife-windows/version.rb +6 -6
  30. data/spec/assets/fake_trusted_certs/excluded.txt +2 -0
  31. data/spec/assets/fake_trusted_certs/github.pem +42 -0
  32. data/spec/assets/fake_trusted_certs/google.crt +41 -0
  33. data/spec/assets/win_fake_trusted_cert_script.txt +89 -0
  34. data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +223 -223
  35. data/spec/assets/win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt +223 -223
  36. data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +335 -335
  37. data/spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt +335 -335
  38. data/spec/assets/win_template_unrendered.txt +246 -246
  39. data/spec/dummy_winrm_connection.rb +21 -21
  40. data/spec/functional/bootstrap_download_spec.rb +236 -236
  41. data/spec/spec_helper.rb +94 -94
  42. data/spec/unit/knife/bootstrap_options_spec.rb +157 -157
  43. data/spec/unit/knife/bootstrap_template_spec.rb +98 -98
  44. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +423 -423
  45. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +213 -177
  46. data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
  47. data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
  48. data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
  49. data/spec/unit/knife/winrm_session_spec.rb +95 -95
  50. data/spec/unit/knife/winrm_spec.rb +500 -500
  51. data/spec/unit/knife/wsman_test_spec.rb +209 -209
  52. metadata +7 -3
data/RELEASE_NOTES.md CHANGED
@@ -1,10 +1,10 @@
1
- <!---
2
- This file is reset every time a new release is done. The contents of this file are for the currently unreleased version.
3
-
4
- Example Note:
5
-
6
- ## Example Heading
7
- Details about the thing that changed that needs to get included in the Release Notes in markdown.
8
- -->
9
- # knife-windows 1.6.0 release notes:
1
+ <!---
2
+ This file is reset every time a new release is done. The contents of this file are for the currently unreleased version.
3
+
4
+ Example Note:
5
+
6
+ ## Example Heading
7
+ Details about the thing that changed that needs to get included in the Release Notes in markdown.
8
+ -->
9
+ # knife-windows 1.6.0 release notes:
10
10
  This release adds a `--winrm-shell` argument to `knife winrm`. This accepts one of three possible values: `cmd`, `powershell` or `elevated`. The default value is `cmd`. The `elevated` shell is similar to the `powershell` shell but runs the powershell command from a scheduled task.
data/appveyor.yml CHANGED
@@ -1,39 +1,39 @@
1
- version: "master-{build}"
2
-
3
- os: Windows Server 2012
4
- platform:
5
- - x64
6
-
7
- environment:
8
- bundle_gemfile: ci.gemfile
9
-
10
- matrix:
11
- - ruby_version: "20"
12
- chef_version: "< 12"
13
-
14
- - ruby_version: "23"
15
- chef_version: "~> 12.0"
16
-
17
- - ruby_version: "23"
18
- chef_version: "master"
19
-
20
- clone_folder: c:\projects\knife-windows
21
- clone_depth: 1
22
- branches:
23
- only:
24
- - master
25
-
26
- install:
27
- - winrm quickconfig -q
28
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
29
- - echo %PATH%
30
- - ruby --version
31
- - gem --version
32
- - gem install bundler -v 1.11.2 --quiet --no-ri --no-rdoc
33
- - bundler --version
34
-
35
- build_script:
36
- - bundle install || bundle install || bundle install
37
-
38
- test_script:
39
- - bundle exec rake
1
+ version: "master-{build}"
2
+
3
+ os: Windows Server 2012
4
+ platform:
5
+ - x64
6
+
7
+ environment:
8
+ bundle_gemfile: ci.gemfile
9
+
10
+ matrix:
11
+ - ruby_version: "20"
12
+ chef_version: "< 12"
13
+
14
+ - ruby_version: "23"
15
+ chef_version: "~> 12.0"
16
+
17
+ - ruby_version: "23"
18
+ chef_version: "master"
19
+
20
+ clone_folder: c:\projects\knife-windows
21
+ clone_depth: 1
22
+ branches:
23
+ only:
24
+ - master
25
+
26
+ install:
27
+ - winrm quickconfig -q
28
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
29
+ - echo %PATH%
30
+ - ruby --version
31
+ - gem --version
32
+ - gem install bundler -v 1.11.2 --quiet --no-ri --no-rdoc
33
+ - bundler --version
34
+
35
+ build_script:
36
+ - bundle install || bundle install || bundle install
37
+
38
+ test_script:
39
+ - bundle exec rake
data/ci.gemfile CHANGED
@@ -1,16 +1,16 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in knife-windows.gemspec
4
- gemspec
5
-
6
- if ENV['CHEF_VERSION'] == 'master'
7
- gem 'chef', github: 'chef/chef'
8
- else
9
- gem 'chef', ENV['CHEF_VERSION']
10
- end
11
-
12
- gem "rspec", '~> 3.0'
13
- gem "ruby-wmi"
14
- gem "httpclient"
15
- gem 'rake'
16
- gem "rack", "< 2.0" # 2.0 requires Ruby 2.2+
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-windows.gemspec
4
+ gemspec
5
+
6
+ if ENV['CHEF_VERSION'] == 'master'
7
+ gem 'chef', github: 'chef/chef'
8
+ else
9
+ gem 'chef', ENV['CHEF_VERSION']
10
+ end
11
+
12
+ gem "rspec", '~> 3.0'
13
+ gem "ruby-wmi"
14
+ gem "httpclient"
15
+ gem 'rake'
16
+ gem "rack", "< 2.0" # 2.0 requires Ruby 2.2+
@@ -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@chef.io"]
11
- s.license = "Apache-2.0"
12
- s.homepage = "https://github.com/chef/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", "~> 2.1"
18
- s.add_dependency "winrm-elevated", "~> 1.0"
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@chef.io"]
11
+ s.license = "Apache-2.0"
12
+ s.homepage = "https://github.com/chef/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", "~> 2.1"
18
+ s.add_dependency "winrm-elevated", "~> 1.0"
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,246 +1,246 @@
1
- @rem
2
- @rem Author:: Seth Chisamore (<schisamo@chef.io>)
3
- @rem Copyright:: Copyright (c) 2011-2016 Chef Software, 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
- <% if knife_config[:architecture] %>
91
- @set MACHINE_ARCH=<%= knife_config[:architecture] %>
92
-
93
- <% if knife_config[:architecture] == "x86_64" %>
94
- IF "%PROCESSOR_ARCHITECTURE%"=="x86" IF not defined PROCESSOR_ARCHITEW6432 (
95
- echo You specified bootstrap_architecture as x86_64 but the target machine is i386. A 64 bit program cannot run on a 32 bit machine. > "&2"
96
- echo Exiting without bootstrapping. > "&2"
97
- exit /b 1
98
- )
99
- <% end %>
100
- <% else %>
101
- @set MACHINE_ARCH=x86_64
102
- IF "%PROCESSOR_ARCHITECTURE%"=="x86" IF not defined PROCESSOR_ARCHITEW6432 @set MACHINE_ARCH=i686
103
- <% end %>
104
- goto install
105
-
106
- :install
107
- @rem If user has provided the custom installation command for chef-client then execute it
108
- <% if @chef_config[:knife][:bootstrap_install_command] %>
109
- <%= @chef_config[:knife][:bootstrap_install_command] %>
110
- <% else %>
111
- @rem Install Chef using chef-client MSI installer
112
-
113
- @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
114
- @set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
115
-
116
- @rem Clear any pre-existing downloads
117
- @echo Checking for existing downloaded package at "%LOCAL_DESTINATION_MSI_PATH%"
118
- @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
119
- @echo Found existing downloaded package, deleting.
120
- @del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
121
- @if ERRORLEVEL 1 (
122
- echo Warning: Failed to delete pre-existing package with status code !ERRORLEVEL! > "&2"
123
- )
124
- ) else (
125
- echo No existing downloaded packages to delete.
126
- )
127
-
128
- @rem If there is somehow a name collision, remove pre-existing log
129
- @if EXIST "%CHEF_CLIENT_MSI_LOG_PATH%" del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
130
-
131
- @echo Attempting to download client package using PowerShell if available...
132
- @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%', 'PowerShell') %>"
133
- @set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -InputFormat None -NoProfile -NonInteractive -File <%= bootstrap_directory %>\wget.ps1 "%REMOTE_SOURCE_MSI_URL%" "%LOCAL_DESTINATION_MSI_PATH%"
134
- @echo !powershell_download!
135
- @call !powershell_download!
136
-
137
- @set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
138
-
139
- @if ERRORLEVEL 1 (
140
- @echo Failed PowerShell 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 PowerShell 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 cscript ...
156
-
157
- @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
158
-
159
- @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%') %>"
160
- cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
161
-
162
- @if NOT ERRORLEVEL 1 (
163
- @rem Sometimes the error level is not set even when the download failed,
164
- @rem so check for the file to be sure it is there.
165
- @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
166
- echo Failed download: download completed, but downloaded file not found > "&2"
167
- echo Exiting without bootstrapping due to download failure. > "&2"
168
- exit /b 1
169
- ) else (
170
- echo Download via cscript succeeded.
171
- )
172
- ) else (
173
- echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
174
- echo Exiting without bootstrapping due to download failure. > "&2"
175
- exit /b 1
176
- )
177
- )
178
-
179
- @echo Installing downloaded client package...
180
-
181
- <%= install_chef %>
182
-
183
- @if ERRORLEVEL 1 (
184
- echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
185
- echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
186
- ) else (
187
- @echo Installation completed successfully
188
- del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
189
- )
190
-
191
- <% end %>
192
-
193
- @endlocal
194
-
195
- @echo off
196
-
197
- <% if client_pem -%>
198
- > <%= bootstrap_directory %>\client.pem (
199
- <%= escape_and_echo(::File.read(::File.expand_path(client_pem))) %>
200
- )
201
- <% end -%>
202
-
203
- echo Writing validation key...
204
-
205
- <% if validation_key -%>
206
- > <%= bootstrap_directory %>\validation.pem (
207
- <%= escape_and_echo(validation_key) %>
208
- )
209
- <% end -%>
210
-
211
- echo Validation key written.
212
- @echo on
213
-
214
- <% if @config[:secret] -%>
215
- > <%= bootstrap_directory %>\encrypted_data_bag_secret (
216
- <%= secret %>
217
- )
218
- <% end -%>
219
-
220
- <% unless trusted_certs_script.empty? -%>
221
- mkdir <%= bootstrap_directory %>\trusted_certs
222
- <%= trusted_certs_script %>
223
- <% end -%>
224
-
225
- <%# Generate Ohai Hints -%>
226
- <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
227
- mkdir <%= bootstrap_directory %>\ohai\hints
228
-
229
- <% @chef_config[:knife][:hints].each do |name, hash| -%>
230
- > <%= bootstrap_directory %>\ohai\hints\<%= name %>.json (
231
- <%= escape_and_echo(hash.to_json) %>
232
- )
233
- <% end -%>
234
- <% end -%>
235
-
236
- > <%= bootstrap_directory %>\client.rb (
237
- <%= config_content %>
238
- )
239
-
240
- > <%= bootstrap_directory %>\first-boot.json (
241
- <%= first_boot %>
242
- )
243
-
244
- @echo Starting chef to bootstrap the node...
245
- <%= start_chef %>
246
-
1
+ @rem
2
+ @rem Author:: Seth Chisamore (<schisamo@chef.io>)
3
+ @rem Copyright:: Copyright (c) 2011-2016 Chef Software, 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
+ <% if knife_config[:architecture] %>
91
+ @set MACHINE_ARCH=<%= knife_config[:architecture] %>
92
+
93
+ <% if knife_config[:architecture] == "x86_64" %>
94
+ IF "%PROCESSOR_ARCHITECTURE%"=="x86" IF not defined PROCESSOR_ARCHITEW6432 (
95
+ echo You specified bootstrap_architecture as x86_64 but the target machine is i386. A 64 bit program cannot run on a 32 bit machine. > "&2"
96
+ echo Exiting without bootstrapping. > "&2"
97
+ exit /b 1
98
+ )
99
+ <% end %>
100
+ <% else %>
101
+ @set MACHINE_ARCH=x86_64
102
+ IF "%PROCESSOR_ARCHITECTURE%"=="x86" IF not defined PROCESSOR_ARCHITEW6432 @set MACHINE_ARCH=i686
103
+ <% end %>
104
+ goto install
105
+
106
+ :install
107
+ @rem If user has provided the custom installation command for chef-client then execute it
108
+ <% if @chef_config[:knife][:bootstrap_install_command] %>
109
+ <%= @chef_config[:knife][:bootstrap_install_command] %>
110
+ <% else %>
111
+ @rem Install Chef using chef-client MSI installer
112
+
113
+ @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
114
+ @set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
115
+
116
+ @rem Clear any pre-existing downloads
117
+ @echo Checking for existing downloaded package at "%LOCAL_DESTINATION_MSI_PATH%"
118
+ @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
119
+ @echo Found existing downloaded package, deleting.
120
+ @del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
121
+ @if ERRORLEVEL 1 (
122
+ echo Warning: Failed to delete pre-existing package with status code !ERRORLEVEL! > "&2"
123
+ )
124
+ ) else (
125
+ echo No existing downloaded packages to delete.
126
+ )
127
+
128
+ @rem If there is somehow a name collision, remove pre-existing log
129
+ @if EXIST "%CHEF_CLIENT_MSI_LOG_PATH%" del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
130
+
131
+ @echo Attempting to download client package using PowerShell if available...
132
+ @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%', 'PowerShell') %>"
133
+ @set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -InputFormat None -NoProfile -NonInteractive -File <%= bootstrap_directory %>\wget.ps1 "%REMOTE_SOURCE_MSI_URL%" "%LOCAL_DESTINATION_MSI_PATH%"
134
+ @echo !powershell_download!
135
+ @call !powershell_download!
136
+
137
+ @set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
138
+
139
+ @if ERRORLEVEL 1 (
140
+ @echo Failed PowerShell 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 PowerShell 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 cscript ...
156
+
157
+ @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
158
+
159
+ @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%') %>"
160
+ cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
161
+
162
+ @if NOT ERRORLEVEL 1 (
163
+ @rem Sometimes the error level is not set even when the download failed,
164
+ @rem so check for the file to be sure it is there.
165
+ @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
166
+ echo Failed download: download completed, but downloaded file not found > "&2"
167
+ echo Exiting without bootstrapping due to download failure. > "&2"
168
+ exit /b 1
169
+ ) else (
170
+ echo Download via cscript succeeded.
171
+ )
172
+ ) else (
173
+ echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
174
+ echo Exiting without bootstrapping due to download failure. > "&2"
175
+ exit /b 1
176
+ )
177
+ )
178
+
179
+ @echo Installing downloaded client package...
180
+
181
+ <%= install_chef %>
182
+
183
+ @if ERRORLEVEL 1 (
184
+ echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
185
+ echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
186
+ ) else (
187
+ @echo Installation completed successfully
188
+ del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
189
+ )
190
+
191
+ <% end %>
192
+
193
+ @endlocal
194
+
195
+ @echo off
196
+
197
+ <% if client_pem -%>
198
+ > <%= bootstrap_directory %>\client.pem (
199
+ <%= escape_and_echo(::File.read(::File.expand_path(client_pem))) %>
200
+ )
201
+ <% end -%>
202
+
203
+ echo Writing validation key...
204
+
205
+ <% if validation_key -%>
206
+ > <%= bootstrap_directory %>\validation.pem (
207
+ <%= escape_and_echo(validation_key) %>
208
+ )
209
+ <% end -%>
210
+
211
+ echo Validation key written.
212
+ @echo on
213
+
214
+ <% if @config[:secret] -%>
215
+ > <%= bootstrap_directory %>\encrypted_data_bag_secret (
216
+ <%= secret %>
217
+ )
218
+ <% end -%>
219
+
220
+ <% unless trusted_certs_script.empty? -%>
221
+ mkdir <%= bootstrap_directory %>\trusted_certs
222
+ <%= trusted_certs_script %>
223
+ <% end -%>
224
+
225
+ <%# Generate Ohai Hints -%>
226
+ <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
227
+ mkdir <%= bootstrap_directory %>\ohai\hints
228
+
229
+ <% @chef_config[:knife][:hints].each do |name, hash| -%>
230
+ > <%= bootstrap_directory %>\ohai\hints\<%= name %>.json (
231
+ <%= escape_and_echo(hash.to_json) %>
232
+ )
233
+ <% end -%>
234
+ <% end -%>
235
+
236
+ > <%= bootstrap_directory %>\client.rb (
237
+ <%= config_content %>
238
+ )
239
+
240
+ > <%= bootstrap_directory %>\first-boot.json (
241
+ <%= first_boot %>
242
+ )
243
+
244
+ @echo Starting chef to bootstrap the node...
245
+ <%= start_chef %>
246
+