knife-windows 1.0.0.rc.1 → 1.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -5
  3. data/.travis.yml +20 -20
  4. data/CHANGELOG.md +75 -74
  5. data/DOC_CHANGES.md +323 -323
  6. data/Gemfile +12 -12
  7. data/LICENSE +201 -201
  8. data/README.md +393 -292
  9. data/RELEASE_NOTES.md +79 -74
  10. data/Rakefile +21 -16
  11. data/appveyor.yml +42 -42
  12. data/ci.gemfile +15 -15
  13. data/features/knife_help.feature +20 -20
  14. data/features/support/env.rb +5 -5
  15. data/knife-windows.gemspec +28 -28
  16. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +247 -241
  17. data/lib/chef/knife/bootstrap_windows_base.rb +388 -368
  18. data/lib/chef/knife/bootstrap_windows_ssh.rb +110 -110
  19. data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -113
  20. data/lib/chef/knife/core/windows_bootstrap_context.rb +361 -362
  21. data/lib/chef/knife/knife_windows_base.rb +33 -0
  22. data/lib/chef/knife/windows_cert_generate.rb +155 -155
  23. data/lib/chef/knife/windows_cert_install.rb +68 -68
  24. data/lib/chef/knife/windows_helper.rb +36 -36
  25. data/lib/chef/knife/windows_listener_create.rb +107 -107
  26. data/lib/chef/knife/winrm.rb +212 -191
  27. data/lib/chef/knife/winrm_base.rb +118 -125
  28. data/lib/chef/knife/winrm_knife_base.rb +218 -201
  29. data/lib/chef/knife/winrm_session.rb +80 -71
  30. data/lib/chef/knife/winrm_shared_options.rb +47 -47
  31. data/lib/chef/knife/wsman_endpoint.rb +44 -44
  32. data/lib/chef/knife/wsman_test.rb +96 -96
  33. data/lib/knife-windows/path_helper.rb +234 -234
  34. data/lib/knife-windows/version.rb +6 -6
  35. data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +217 -0
  36. data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +329 -0
  37. data/spec/assets/win_template_unrendered.txt +246 -0
  38. data/spec/functional/bootstrap_download_spec.rb +216 -140
  39. data/spec/spec_helper.rb +87 -72
  40. data/spec/unit/knife/bootstrap_options_spec.rb +146 -146
  41. data/spec/unit/knife/bootstrap_template_spec.rb +92 -92
  42. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +240 -161
  43. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +151 -101
  44. data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
  45. data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
  46. data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
  47. data/spec/unit/knife/winrm_session_spec.rb +55 -46
  48. data/spec/unit/knife/winrm_spec.rb +504 -376
  49. data/spec/unit/knife/wsman_test_spec.rb +175 -175
  50. metadata +28 -8
data/RELEASE_NOTES.md CHANGED
@@ -1,74 +1,79 @@
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.0.0.rc.0 release notes:
10
- This release of knife-windows includes new features to improve authentication,
11
- simplify use of the WinRM SSL transport, and addresses compatibility issues with Chef Client 12.0.
12
-
13
- You can install the new features using the `gem` command:
14
-
15
- gem install knife-windows --pre
16
-
17
- ## Reporting issues and contributing
18
-
19
- `knife-windows` issues like those addressed in this release should be reported in the ticketing system at https://github.com/chef/knife-windows/issues. You can learn more about how to contribute features and bug fixes to `knife-windows` in the [Chef Contributions document](http://docs.chef.io/community_contributions.html).
20
-
21
- ## Breaking changes
22
-
23
- ### Negotiate as the default authentication protocol
24
- With this release, the default authentication protocol for WinRM
25
- communication is negotiate, which is the same as that for tools built-in to
26
- the Windows operating system. Prior to this release, the protocol depended
27
- on the format of the `--winrm-user` option -- the basic authentication
28
- protocol would be assumed unless that option had the format `domain\user`.
29
-
30
- To revert to the behavior of previous releases or otherwise force `knife-windows` to use a specific authentication protocol such as
31
- basic, use the `--winrm-authentication-protocol` option.
32
-
33
- ### Default WinRM port depends on the transport
34
- The default port for WinRM communication is now **5986** when the SSL transport is used (the transport is
35
- configured by the `winrm_transport` option), otherwise it is **5985**. In
36
- previous releases, if the port was not specified, it was always 5985.
37
-
38
- To override this behavior, explicitly specify the desired port using the
39
- `winrm_port` (`-p`) option.
40
-
41
- ### Kerberos Keytab short option is now -T
42
- The short option flag for --keytab-file is now -T to fix a conflict with the --identity-file option.
43
-
44
- ## Features added in knife-windows 1.0.0.rc.0
45
- * New `--winrm-authentication-protocol` option for explicit control of WinRM authentication
46
- * `knife windows cert generate` subcommand:
47
- Generates a certificate and related public key file for use in configuring a WinRM listener and validating communication involving it.
48
- * `knife windows cert install` subcommand:
49
- Installs a certificate such as one generated by the `cert generate`
50
- subcommand into the Windows certificate store's LocalMachine personal store
51
- so that it can be used as part of the configuration for a WinRM SSL listener
52
- * `knife windows listener create` subcommand:
53
- Creates a WinRM SSL listener on a Windows system
54
- * Added `--hint` option for creating Ohai hints on bootstrap
55
- * Validatorless bootstrapping is now supported
56
- * New `--install-as-service` option will have Chef Client be installed as a service on bootstrap
57
- * Added `--msi_url` option for providing an alternate URL to the Chef Client installation package
58
- * `knife wsman test` subcommaned:
59
- Verifies winrm functionality on a remote system, e.g. `knife wsman test 192.168.1.10 -m --winrm-transport ssl`
60
-
61
- ## Issues fixed in knife-windows 1.0.0.rc.0
62
- * [knife-windows #159](https://github.com/chef/knife-windows/issues/159) `winrm_port` option should default to 5986 if `winrm_transport` option is `ssl`
63
- * [knife-windows #139](https://github.com/chef/knife-windows/issues/139) Force dev dependency on Chef 11 for test scenarios to avoid Ohai 8 conflict on Ruby 1.9.x
64
- * [knife-windows #133](https://github.com/chef/knife-windows/issues/133) Bootstrap failure -- unable to validate SSL chef server endpoints
65
- * [knife-windows #125](https://github.com/chef/knife-windows/issues/125) knife-windows should use PowerShell first before cscript to download the Chef Client msi
66
- * [knife-windows #92](https://github.com/chef/knife-windows/issues/92) EventMachine issue: knife bootstrap windows winrm error
67
- * [knife-windows #94](https://github.com/chef/knife-windows/issues/94) Remove Eventmachine dependency
68
- * [knife-windows #213](https://github.com/chef/knife-windows/pull/213) Search possibilities of HOME for bootstrap templates
69
- * [knife-windows #227](https://github.com/chef/knife-windows/issues/227) Exception: NoMethodError: undefined method 'gsub' for false:FalseClass
70
-
71
- ## knife-windows on RubyGems and Github
72
- https://rubygems.org/gems/knife-windows
73
- https://github.com/chef/knife-windows
74
-
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.0.0 release notes:
10
+ This release of knife-windows includes new features to improve authentication,
11
+ simplify use of the WinRM SSL transport, and addresses compatibility issues with Chef Client 12.0.
12
+
13
+ You can install the new features using the `gem` command:
14
+
15
+ gem install knife-windows
16
+
17
+ Due to dependency conflicts, to use knife-windows 1.0.0+ with ChefDK 0.6.2, you must also upgrade chef-provisioning to 1.2.0+ and update the line referencing chef-provisioning in c:\opscode\chefdk\bin\chef. ChefDK 0.7.0+ will include the latest versions of both knife-windows and chef-provisioning.
18
+
19
+ chef gem install knife-windows
20
+ chef gem install chef-provisioning
21
+
22
+ ## Reporting issues and contributing
23
+
24
+ `knife-windows` issues like those addressed in this release should be reported in the ticketing system at https://github.com/chef/knife-windows/issues. You can learn more about how to contribute features and bug fixes to `knife-windows` in the [Chef Contributions document](http://docs.chef.io/community_contributions.html).
25
+
26
+ ## Breaking changes
27
+
28
+ ### Negotiate as the default authentication protocol
29
+ With this release, the default authentication protocol for WinRM
30
+ communication is negotiate, which is the same as that for tools built-in to
31
+ the Windows operating system. Prior to this release, the protocol depended
32
+ on the format of the `--winrm-user` option -- the basic authentication
33
+ protocol would be assumed unless that option had the format `domain\user`.
34
+
35
+ To revert to the behavior of previous releases or otherwise force `knife-windows` to use a specific authentication protocol such as
36
+ basic, use the `--winrm-authentication-protocol` option.
37
+
38
+ ### Default WinRM port depends on the transport
39
+ The default port for WinRM communication is now **5986** when the SSL transport is used (the transport is
40
+ configured by the `winrm_transport` option), otherwise it is **5985**. In
41
+ previous releases, if the port was not specified, it was always 5985.
42
+
43
+ To override this behavior, explicitly specify the desired port using the
44
+ `winrm_port` (`-p`) option.
45
+
46
+ ### Kerberos Keytab short option is now -T
47
+ The short option flag for --keytab-file is now -T to fix a conflict with the --identity-file option.
48
+
49
+ ## Features added in knife-windows 1.0.0
50
+ * New `--winrm-authentication-protocol` option for explicit control of WinRM authentication
51
+ * `knife windows cert generate` subcommand:
52
+ Generates a certificate and related public key file for use in configuring a WinRM listener and validating communication involving it.
53
+ * `knife windows cert install` subcommand:
54
+ Installs a certificate such as one generated by the `cert generate`
55
+ subcommand into the Windows certificate store's LocalMachine personal store
56
+ so that it can be used as part of the configuration for a WinRM SSL listener
57
+ * `knife windows listener create` subcommand:
58
+ Creates a WinRM SSL listener on a Windows system
59
+ * Added `--hint` option for creating Ohai hints on bootstrap
60
+ * Validatorless bootstrapping is now supported
61
+ * New `--install-as-service` option will have Chef Client be installed as a service on bootstrap
62
+ * Added `--msi_url` option for providing an alternate URL to the Chef Client installation package
63
+ * `knife wsman test` subcommaned:
64
+ Verifies winrm functionality on a remote system, e.g. `knife wsman test 192.168.1.10 -m --winrm-transport ssl`
65
+
66
+ ## Issues fixed in knife-windows 1.0.0
67
+ * [knife-windows #159](https://github.com/chef/knife-windows/issues/159) `winrm_port` option should default to 5986 if `winrm_transport` option is `ssl`
68
+ * [knife-windows #139](https://github.com/chef/knife-windows/issues/139) Force dev dependency on Chef 11 for test scenarios to avoid Ohai 8 conflict on Ruby 1.9.x
69
+ * [knife-windows #133](https://github.com/chef/knife-windows/issues/133) Bootstrap failure -- unable to validate SSL chef server endpoints
70
+ * [knife-windows #125](https://github.com/chef/knife-windows/issues/125) knife-windows should use PowerShell first before cscript to download the Chef Client msi
71
+ * [knife-windows #92](https://github.com/chef/knife-windows/issues/92) EventMachine issue: knife bootstrap windows winrm error
72
+ * [knife-windows #94](https://github.com/chef/knife-windows/issues/94) Remove Eventmachine dependency
73
+ * [knife-windows #213](https://github.com/chef/knife-windows/pull/213) Search possibilities of HOME for bootstrap templates
74
+ * [knife-windows #227](https://github.com/chef/knife-windows/issues/227) Exception: NoMethodError: undefined method 'gsub' for false:FalseClass
75
+
76
+ ## knife-windows on RubyGems and Github
77
+ https://rubygems.org/gems/knife-windows
78
+ https://github.com/chef/knife-windows
79
+
data/Rakefile CHANGED
@@ -1,16 +1,21 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- begin
5
- require 'rspec/core/rake_task'
6
-
7
- task :default => :spec
8
-
9
- desc "Run all specs in spec directory"
10
- RSpec::Core::RakeTask.new(:spec) do |t|
11
- t.pattern = 'spec/**/*_spec.rb'
12
- end
13
-
14
- rescue LoadError
15
- STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
16
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+
7
+ task :default => [:unit_spec, :functional_spec]
8
+
9
+ desc "Run all functional specs in spec directory"
10
+ RSpec::Core::RakeTask.new(:functional_spec) do |t|
11
+ t.pattern = 'spec/functional/**/*_spec.rb'
12
+ end
13
+
14
+ desc "Run all unit specs in spec directory"
15
+ RSpec::Core::RakeTask.new(:unit_spec) do |t|
16
+ t.pattern = 'spec/unit/**/*_spec.rb'
17
+ end
18
+
19
+ rescue LoadError
20
+ STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
21
+ end
data/appveyor.yml CHANGED
@@ -1,42 +1,42 @@
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: "193"
12
- chef_version: "< 12"
13
-
14
- - ruby_version: "200"
15
- chef_version: "< 12"
16
-
17
- - ruby_version: "200"
18
- chef_version: "~> 12.0"
19
-
20
- - ruby_version: "200"
21
- chef_version: "master"
22
-
23
- clone_folder: c:\projects\knife-windows
24
- clone_depth: 1
25
- branches:
26
- only:
27
- - master
28
-
29
- install:
30
- - winrm quickconfig -q
31
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
32
- - echo %PATH%
33
- - ruby --version
34
- - gem --version
35
- - gem install bundler --quiet --no-ri --no-rdoc
36
- - bundler --version
37
-
38
- build_script:
39
- - bundle install || bundle install || bundle install
40
-
41
- test_script:
42
- - bundle exec rake spec
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: "193"
12
+ chef_version: "< 12"
13
+
14
+ - ruby_version: "200"
15
+ chef_version: "< 12"
16
+
17
+ - ruby_version: "200"
18
+ chef_version: "~> 12.0"
19
+
20
+ - ruby_version: "200"
21
+ chef_version: "master"
22
+
23
+ clone_folder: c:\projects\knife-windows
24
+ clone_depth: 1
25
+ branches:
26
+ only:
27
+ - master
28
+
29
+ install:
30
+ - winrm quickconfig -q
31
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
32
+ - echo %PATH%
33
+ - ruby --version
34
+ - gem --version
35
+ - gem install bundler --quiet --no-ri --no-rdoc
36
+ - bundler --version
37
+
38
+ build_script:
39
+ - bundle install || bundle install || bundle install
40
+
41
+ test_script:
42
+ - bundle exec rake
data/ci.gemfile CHANGED
@@ -1,15 +1,15 @@
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'
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'
@@ -1,20 +1,20 @@
1
- Feature: Ensure that the help works as designed
2
- In order to test the help via CLI
3
- As an Operator
4
- I want to run the CLI with different arguments
5
-
6
- Scenario: Running the windows sub-command shows available commands
7
- When I run `knife windows`
8
- And the output should contain "Available windows subcommands: (for details, knife SUB-COMMAND --help)\n\n** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
9
-
10
- Scenario: Running the windows sub-command shows available commands
11
- When I run `knife windows --help`
12
- And the output should contain "Available windows subcommands: (for details, knife SUB-COMMAND --help)\n\n** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
13
-
14
- Scenario: Running the windows sub-command shows available commands
15
- When I run `knife windows help`
16
- And the output should contain "Available windows subcommands: (for details, knife SUB-COMMAND --help)\n\n** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
17
-
18
- Scenario: Running the knife command shows available windows command"
19
- When I run `knife`
20
- And the output should contain "** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
1
+ Feature: Ensure that the help works as designed
2
+ In order to test the help via CLI
3
+ As an Operator
4
+ I want to run the CLI with different arguments
5
+
6
+ Scenario: Running the windows sub-command shows available commands
7
+ When I run `knife windows`
8
+ And the output should contain "Available windows subcommands: (for details, knife SUB-COMMAND --help)\n\n** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
9
+
10
+ Scenario: Running the windows sub-command shows available commands
11
+ When I run `knife windows --help`
12
+ And the output should contain "Available windows subcommands: (for details, knife SUB-COMMAND --help)\n\n** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
13
+
14
+ Scenario: Running the windows sub-command shows available commands
15
+ When I run `knife windows help`
16
+ And the output should contain "Available windows subcommands: (for details, knife SUB-COMMAND --help)\n\n** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
17
+
18
+ Scenario: Running the knife command shows available windows command"
19
+ When I run `knife`
20
+ And the output should contain "** WINDOWS COMMANDS **\nknife bootstrap windows winrm FQDN (options)\nknife bootstrap windows ssh FQDN (options)\nknife winrm QUERY COMMAND (options)"
@@ -1,5 +1,5 @@
1
- require 'aruba/cucumber'
2
-
3
- Before do
4
- @aruba_timeout_seconds = 5
5
- end
1
+ require 'aruba/cucumber'
2
+
3
+ Before do
4
+ @aruba_timeout_seconds = 5
5
+ end
@@ -1,28 +1,28 @@
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", "~> 1.3"
18
- s.add_dependency "winrm-s", "~> 0.3.0.dev.0"
19
- s.add_dependency "nokogiri"
20
-
21
- s.add_development_dependency 'pry'
22
-
23
- s.files = `git ls-files`.split("\n")
24
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
- s.require_paths = ["lib"]
27
- end
28
-
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", "~> 1.3"
18
+ s.add_dependency "winrm-s", "~> 0.3.0"
19
+ s.add_dependency "nokogiri"
20
+
21
+ s.add_development_dependency 'pry'
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
28
+
@@ -1,241 +1,247 @@
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
- @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
111
- @set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
112
-
113
- @rem Clear any pre-existing downloads
114
- @echo Checking for existing downloaded package at "%LOCAL_DESTINATION_MSI_PATH%"
115
- @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
116
- @echo Found existing downloaded package, deleting.
117
- @del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
118
- @if ERRORLEVEL 1 (
119
- echo Warning: Failed to delete pre-existing package with status code !ERRORLEVEL! > "&2"
120
- )
121
- ) else (
122
- echo No existing downloaded packages to delete.
123
- )
124
-
125
- @rem If there is somehow a name collision, remove pre-existing log
126
- @if EXIST "%CHEF_CLIENT_MSI_LOG_PATH%" del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
127
-
128
- @echo Attempting to download client package using PowerShell if available...
129
- @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%', 'PowerShell') %>"
130
- @set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File <%= bootstrap_directory %>\wget.ps1 "%REMOTE_SOURCE_MSI_URL%" "%LOCAL_DESTINATION_MSI_PATH%"
131
- @echo !powershell_download!
132
- @call !powershell_download!
133
-
134
- @set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
135
-
136
- @if ERRORLEVEL 1 (
137
- @echo Failed PowerShell download with status code !DOWNLOAD_ERROR_STATUS! > "&2"
138
- @if !DOWNLOAD_ERROR_STATUS!==0 set DOWNLOAD_ERROR_STATUS=2
139
- ) else (
140
- @rem Sometimes the error level is not set even when the download failed,
141
- @rem so check for the file to be sure it is there -- if it is not, we will retry
142
- @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
143
- echo Failed download: download completed, but downloaded file not found > "&2"
144
- set DOWNLOAD_ERROR_STATUS=2
145
- ) else (
146
- echo Download via PowerShell succeeded.
147
- )
148
- )
149
-
150
- @if NOT %DOWNLOAD_ERROR_STATUS%==0 (
151
- @echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
152
- @echo Warning: Retrying download with cscript ...
153
-
154
- @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
155
-
156
- @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%') %>"
157
- cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
158
-
159
- @if NOT ERRORLEVEL 1 (
160
- @rem Sometimes the error level is not set even when the download failed,
161
- @rem so check for the file to be sure it is there.
162
- @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
163
- echo Failed download: download completed, but downloaded file not found > "&2"
164
- echo Exiting without bootstrapping due to download failure. > "&2"
165
- exit /b 1
166
- ) else (
167
- echo Download via cscript succeeded.
168
- )
169
- ) else (
170
- echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
171
- echo Exiting without bootstrapping due to download failure. > "&2"
172
- exit /b 1
173
- )
174
- )
175
-
176
- @echo Installing downloaded client package...
177
-
178
- <%= install_chef %>
179
-
180
- @if ERRORLEVEL 1 (
181
- echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
182
- echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
183
- ) else (
184
- @echo Installation completed successfully
185
- del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
186
- )
187
-
188
- @endlocal
189
-
190
- @echo off
191
-
192
- <% if client_pem -%>
193
- > <%= bootstrap_directory %>\client.pem (
194
- <%= escape_and_echo(::File.read(::File.expand_path(client_pem))) %>
195
- )
196
- <% end -%>
197
-
198
- echo Writing validation key...
199
-
200
- <% if validation_key -%>
201
- > <%= bootstrap_directory %>\validation.pem (
202
- <%= escape_and_echo(validation_key) %>
203
- )
204
- <% end -%>
205
-
206
- echo Validation key written.
207
- @echo on
208
-
209
- <% if @config[:secret] -%>
210
- > <%= bootstrap_directory %>\encrypted_data_bag_secret (
211
- <%= secret %>
212
- )
213
- <% end -%>
214
-
215
- <% unless trusted_certs_script.empty? -%>
216
- mkdir <%= bootstrap_directory %>\trusted_certs
217
- <%= trusted_certs_script %>
218
- <% end -%>
219
-
220
- <%# Generate Ohai Hints -%>
221
- <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
222
- mkdir <%= bootstrap_directory %>\ohai\hints
223
-
224
- <% @chef_config[:knife][:hints].each do |name, hash| -%>
225
- > <%= bootstrap_directory %>\ohai\hints\<%= name %>.json (
226
- <%= escape_and_echo(hash.to_json) %>
227
- )
228
- <% end -%>
229
- <% end -%>
230
-
231
- > <%= bootstrap_directory %>\client.rb (
232
- <%= config_content %>
233
- )
234
-
235
- > <%= bootstrap_directory %>\first-boot.json (
236
- <%= first_boot %>
237
- )
238
-
239
- @echo Starting chef to bootstrap the node...
240
- <%= start_chef %>
241
-
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 If user has provided the custom installation command for chef-client then execute it
109
+ <% if @chef_config[:knife][:bootstrap_install_command] %>
110
+ <%= @chef_config[:knife][:bootstrap_install_command] %>
111
+ <% else %>
112
+ @rem Install Chef using chef-client MSI installer
113
+
114
+ @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
115
+ @set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
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 PowerShell if available...
133
+ @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%', 'PowerShell') %>"
134
+ @set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File <%= bootstrap_directory %>\wget.ps1 "%REMOTE_SOURCE_MSI_URL%" "%LOCAL_DESTINATION_MSI_PATH%"
135
+ @echo !powershell_download!
136
+ @call !powershell_download!
137
+
138
+ @set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
139
+
140
+ @if ERRORLEVEL 1 (
141
+ @echo Failed PowerShell download with status code !DOWNLOAD_ERROR_STATUS! > "&2"
142
+ @if !DOWNLOAD_ERROR_STATUS!==0 set DOWNLOAD_ERROR_STATUS=2
143
+ ) else (
144
+ @rem Sometimes the error level is not set even when the download failed,
145
+ @rem so check for the file to be sure it is there -- if it is not, we will retry
146
+ @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
147
+ echo Failed download: download completed, but downloaded file not found > "&2"
148
+ set DOWNLOAD_ERROR_STATUS=2
149
+ ) else (
150
+ echo Download via PowerShell succeeded.
151
+ )
152
+ )
153
+
154
+ @if NOT %DOWNLOAD_ERROR_STATUS%==0 (
155
+ @echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
156
+ @echo Warning: Retrying download with cscript ...
157
+
158
+ @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
159
+
160
+ @set "REMOTE_SOURCE_MSI_URL=<%= msi_url('%MACHINE_OS%', '%MACHINE_ARCH%') %>"
161
+ cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
162
+
163
+ @if NOT ERRORLEVEL 1 (
164
+ @rem Sometimes the error level is not set even when the download failed,
165
+ @rem so check for the file to be sure it is there.
166
+ @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
167
+ echo Failed download: download completed, but downloaded file not found > "&2"
168
+ echo Exiting without bootstrapping due to download failure. > "&2"
169
+ exit /b 1
170
+ ) else (
171
+ echo Download via cscript succeeded.
172
+ )
173
+ ) else (
174
+ echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
175
+ echo Exiting without bootstrapping due to download failure. > "&2"
176
+ exit /b 1
177
+ )
178
+ )
179
+
180
+ @echo Installing downloaded client package...
181
+
182
+ <%= install_chef %>
183
+
184
+ @if ERRORLEVEL 1 (
185
+ echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
186
+ echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
187
+ ) else (
188
+ @echo Installation completed successfully
189
+ del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
190
+ )
191
+
192
+ <% end %>
193
+
194
+ @endlocal
195
+
196
+ @echo off
197
+
198
+ <% if client_pem -%>
199
+ > <%= bootstrap_directory %>\client.pem (
200
+ <%= escape_and_echo(::File.read(::File.expand_path(client_pem))) %>
201
+ )
202
+ <% end -%>
203
+
204
+ echo Writing validation key...
205
+
206
+ <% if validation_key -%>
207
+ > <%= bootstrap_directory %>\validation.pem (
208
+ <%= escape_and_echo(validation_key) %>
209
+ )
210
+ <% end -%>
211
+
212
+ echo Validation key written.
213
+ @echo on
214
+
215
+ <% if @config[:secret] -%>
216
+ > <%= bootstrap_directory %>\encrypted_data_bag_secret (
217
+ <%= secret %>
218
+ )
219
+ <% end -%>
220
+
221
+ <% unless trusted_certs_script.empty? -%>
222
+ mkdir <%= bootstrap_directory %>\trusted_certs
223
+ <%= trusted_certs_script %>
224
+ <% end -%>
225
+
226
+ <%# Generate Ohai Hints -%>
227
+ <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
228
+ mkdir <%= bootstrap_directory %>\ohai\hints
229
+
230
+ <% @chef_config[:knife][:hints].each do |name, hash| -%>
231
+ > <%= bootstrap_directory %>\ohai\hints\<%= name %>.json (
232
+ <%= escape_and_echo(hash.to_json) %>
233
+ )
234
+ <% end -%>
235
+ <% end -%>
236
+
237
+ > <%= bootstrap_directory %>\client.rb (
238
+ <%= config_content %>
239
+ )
240
+
241
+ > <%= bootstrap_directory %>\first-boot.json (
242
+ <%= first_boot %>
243
+ )
244
+
245
+ @echo Starting chef to bootstrap the node...
246
+ <%= start_chef %>
247
+