realityforge-knife-windows 0.5.14

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p327
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -fs
3
+
data/CHANGELOG ADDED
@@ -0,0 +1,14 @@
1
+ Release Notes - Knife Windows Plugin - Version 0.5.6
2
+
3
+ ** New Feature
4
+ * new default bootstrap template that installs Chef using official chef-client MSI installer
5
+
6
+ Release Notes - Knife Windows Plugin - Version 0.5.4
7
+
8
+ ** Bug
9
+ * [KNIFE_WINDOWS-7] - Exception: NoMethodError: undefined method `env_namespace' for Savon:Module
10
+ * [KNIFE_WINDOWS-8] - winrm based bootstrap fails with 'Bad HTTP response returned from server (500)'
11
+
12
+
13
+ ** New Feature
14
+ * [KNIFE_WINDOWS-6] - default bootstrap template should support encrypted_data_bag_secret
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in knife-windows.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "rspec"
8
+ gem "ruby-wmi"
9
+ gem "chef"
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,140 @@
1
+ = Knife Windows Plugin
2
+
3
+ = DESCRIPTION:
4
+
5
+ This plugin adds additional functionality to the Chef Knife CLI tool for configuring/interacting with nodes running Microsoft Windows. The subcommands should function on any system running Ruby 1.9.1+ but nodes being configured via these subcommands require Windows Remote Management (WinRM) 1.0+. WinRM allows you to call native objects in Windows. This includes, but is not limited to, running batch scripts, powershell scripts and fetching WMI variables. For more information on WinRM, please visit {Microsoft's WinRM site}[http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx]. You will want to familiarize yourself with (certain key aspects) of WinRM because you will be {writing scripts/running commands} with this tool to get you from (specific point A) to (specific point B).
6
+
7
+ WinRM is built into Windows 7 and Windows Server 2008+. It can also be easily installed in older version of Windows, including:
8
+
9
+ * Windows XP
10
+ * Windows Server 2003
11
+ * Windows Vista
12
+
13
+ More information can be found on {Microsoft Support article 968930}[http://support.microsoft.com/?kbid=968930].
14
+
15
+ This subcommands in this plugin have been tested and verified to work on Windows Server 2008 R2.
16
+
17
+ = SUBCOMMANDS:
18
+
19
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a --+help+ flag
20
+
21
+ == knife winrm
22
+
23
+ The +winrm+ subcommand allows you to invoke commands in parallel on a subset of the nodes in your infrastructure. The +winrm+ subcommand uses the same syntax as the {search subcommand}[http://wiki.opscode.com/display/chef/Search]; you could could find the uptime of all your web servers using the command:
24
+
25
+ % knife winrm "role:web" "net stats srv" -x Administrator -P 'super_secret_password'
26
+
27
+ Or force a chef run:
28
+
29
+ % knife winrm 'ec2-50-xx-xx-124.compute-1.amazonaws.com' 'chef-client -c c:/chef/client.rb' -m -x Administrator -P 'super_secret_password'
30
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:49 +0000] INFO: Starting Chef Run (Version 0.9.12)
31
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:50 +0000] WARN: Node ip-0A502FFB has an empty run list.
32
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Chef Run complete in 4.383966 seconds
33
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: cleaning the checksum cache
34
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Running report handlers
35
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Report handlers complete
36
+
37
+ This subcommand operates in a very similar manner as {knife ssh}[http://wiki.opscode.com/display/chef/Knife#Knife-SSHSubcommand]...just leveraging the WinRM protocol for communication. It also include's +knife+ +ssh+'s "{interactive session mode}[http://wiki.opscode.com/display/chef/Knife#Knife-InteractiveMode]"
38
+
39
+ == knife bootstrap windows winrm
40
+
41
+ Performs a Chef Bootstrap (via the WinRM protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
42
+
43
+ This subcommand operates in a very similar manner as {knife bootstrap}[http://wiki.opscode.com/display/chef/Knife+Bootstrap]...just leveraging the WinRM protocol for communication. An initial run_list for the node can also be passed to the subcommand. Example usage:
44
+
45
+ knife bootstrap windows winrm ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -P 'super_secret_password'
46
+
47
+ == knife bootstrap windows ssh
48
+
49
+ Performs a Chef Bootstrap (via the SSH protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
50
+
51
+ This subcommand assumes the SSH session will use Windows native cmd.exe command shell vs a bash shell through an emulated cygwin layer. Most popular Windows based SSHd daemons like {freeSSHd}[http://www.freesshd.com/] and {WinSSHD}[http://www.bitvise.com/winsshd] behave this way.
52
+
53
+ An initial run_list for the node can also be passed to the subcommand. Example usage:
54
+
55
+ knife bootstrap windows ssh ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -i ~/.ssh/id_rsa
56
+
57
+ = BOOTSTRAP TEMPLATES:
58
+
59
+ This gem provides the following bootstrap templates:
60
+
61
+ == windows-chef-client-msi
62
+
63
+ This bootstrap template does the following:
64
+
65
+ * Installs the latest version of Chef (and all dependencies) using the `chef-client` msi.
66
+ * Writes the validation.pem per the local knife configuration.
67
+ * Writes a default config file for Chef (C:\chef\client.rb) using values from the +knife.rb+.
68
+ * Creates a JSON attributes file containing the specified run list and run Chef.
69
+
70
+ This is the default bootstrap template used by both the +windows+ +bootstrap+ subcommands.
71
+
72
+ == windows-shell
73
+
74
+ This bootstrap template does the following:
75
+
76
+ * Installs Ruby 1.8.7 via the {Ruby Installer for Windows}[http://rubyinstaller.org/] which also includes the latest version of RubyGems
77
+ * Installs the RubyInstaller Development Kit (DevKit). The RubyInstaller Development Kit (DevKit) is a MSYS/MinGW based toolkit than enables you to build many of the native C/C++ extensions available for Ruby.
78
+ * Installs required Windows-related gems from RubyGems.org
79
+ * Installs latest Chef version from RubyGems.org including {Ohai}[https://rubygems.org/gems/ohai] and {Chef}[https://rubygems.org/gems/chef]. The Chef version is configurable using the *--bootstrap-version* option.
80
+ * Writes the validation.pem per the local knife configuration.
81
+ * Writes a default config file for Chef (C:\chef\client.rb) using values from the +knife.rb+.
82
+ * Creates a JSON attributes file containing the specified run list and run Chef.
83
+
84
+ This should be considered a legacy bootstrap template and will most likely be removed in a future version.
85
+
86
+ = REQUIREMENTS/SETUP:
87
+
88
+ == Ruby
89
+
90
+ Ruby 1.9.1+ is needed.
91
+
92
+ == Chef Version
93
+
94
+ Knife plugins require >= Chef 0.10. More details about Knife plugins can be {found on the Chef wiki}[http://wiki.opscode.com/display/chef/Knife+Plugins].
95
+
96
+ == Nodes
97
+
98
+ *NOTE*: Before any WinRM related knife subcommands will function correctly a node's WinRM installation must be configured correctly. The below settings should be added to your base server image (AMI) or passed in using some sort of user-data mechanism provided by your cloud provider.
99
+
100
+ A server running WinRM must also be configured properly to allow outside connections and the entire network path from the knife workstation to the server. The easiest way to accomplish this is to use {WinRM's quick configuration option}[http://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx#quick_default_configuration]:
101
+
102
+ C:\Users\Administrator> winrm quickconfig -q
103
+
104
+ The Chef and Ohai gem installations (that occur during bootstrap) take more memory than the default 150MB WinRM allocates per shell. Bump it up to 300MB with the following setting:
105
+
106
+ C:\Users\Administrator> winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
107
+
108
+ Bootstrap commands can take longer than the WinRM default 60 seconds to complete, bump to 30 minutes:
109
+
110
+ C:\Users\Administrator> winrm set winrm/config @{MaxTimeoutms="1800000"}
111
+
112
+ WinRM supports both the HTTP and HTTPS transports and the following authentication schemes: Kerberos, Digest, Certificate and Basic. The details of these authentication transports are outside of the scope of this README but details can be found on the {WinRM configuration guide}[http://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx]. Currently, this plugin support Kerberos and Basic authentication schemes.
113
+
114
+ For development and testing purposes, unencrypted traffic with Basic authentication can make things easier:
115
+
116
+ C:\Users\Administrator> winrm set winrm/config/service @{AllowUnencrypted="true"}
117
+ C:\Users\Administrator> winrm set winrm/config/service/auth @{Basic="true"}
118
+
119
+ = CONTRIBUTING:
120
+
121
+ Please file bugs against the KNIFE_WINDOWS project at http://tickets.opscode.com/browse/KNIFE_WINDOWS
122
+
123
+ More information on the contribution process for Opscode projects can be found at: http://wiki.opscode.com/display/chef/How+to+Contribute
124
+ = LICENSE:
125
+
126
+ Author:: Seth Chisamore (<schisamo@opscode.com>)
127
+ Copyright:: Copyright (c) 2011 Opscode, Inc.
128
+ License:: Apache License, Version 2.0
129
+
130
+ Licensed under the Apache License, Version 2.0 (the "License");
131
+ you may not use this file except in compliance with the License.
132
+ You may obtain a copy of the License at
133
+
134
+ http://www.apache.org/licenses/LICENSE-2.0
135
+
136
+ Unless required by applicable law or agreed to in writing, software
137
+ distributed under the License is distributed on an "AS IS" BASIS,
138
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139
+ See the License for the specific language governing permissions and
140
+ limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,24 @@
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 = "realityforge-knife-windows"
7
+ s.version = Knife::Windows::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
11
+ s.authors = ["Seth Chisamore"]
12
+ s.email = ["schisamo@opscode.com"]
13
+ s.homepage = "https://github.com/opscode/knife-windows"
14
+ s.summary = %q{Plugin that adds functionality to Chef's Knife CLI for configuring/interacting with nodes running Microsoft Windows}
15
+ s.description = s.summary
16
+
17
+ s.required_ruby_version = ">= 1.9.1"
18
+ s.add_dependency "em-winrm", "= 0.5.4"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,127 @@
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
+ @setlocal
20
+
21
+ <%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
22
+ mkdir <%= bootstrap_directory %>
23
+
24
+ > <%= bootstrap_directory %>\wget.vbs (
25
+ <%= win_wget %>
26
+ )
27
+
28
+ > <%= bootstrap_directory %>\wget.ps1 (
29
+ <%= win_wget_ps %>
30
+ )
31
+
32
+ @rem Determine the version and the architecture
33
+
34
+ FOR /F "tokens=1-8 delims=.[] " %%A IN ('ver') DO (
35
+ @set WinMajor=%%D
36
+ @set WinMinor=%%E
37
+ @set WinBuild=%%F
38
+ )
39
+
40
+ goto Version%WinMajor%.%WinMinor%
41
+
42
+ @rem If this is an unknown version of windows set the default
43
+ @set MACHINE_OS=2008r2
44
+ goto architecture
45
+
46
+ :Version6.0
47
+ @set MACHINE_OS=2008
48
+ goto architecture
49
+
50
+ :Version5.2
51
+ @set MACHINE_OS=2003r2
52
+ goto architecture
53
+
54
+ :Version6.1
55
+ @set MACHINE_OS=2008r2
56
+ goto architecture
57
+
58
+ :Version6.2
59
+ @set MACHINE_OS=2012
60
+ goto architecture
61
+
62
+ :architecture
63
+
64
+ goto Architecture%PROCESSOR_ARCHITECTURE%
65
+
66
+ @rem If this is an unknown architecture set the default
67
+ @set MACHINE_ARCH=i686
68
+ goto install
69
+
70
+ :Architecturex86
71
+ @set MACHINE_ARCH=i686
72
+ goto install
73
+
74
+ :Architectureamd64
75
+ @set MACHINE_ARCH=x86_64
76
+ goto install
77
+
78
+ :install
79
+ @rem Install Chef using chef-client MSI installer
80
+
81
+ @set "REMOTE_SOURCE_MSI_URL=https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%"
82
+ @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
83
+ @set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
84
+
85
+ cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
86
+
87
+ @rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
88
+ @rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
89
+ @rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
90
+ @if ERRORLEVEL 1 (
91
+ echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
92
+ echo Warning: Retrying download with PowerShell if available
93
+ if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
94
+ @powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive "& '<%= bootstrap_directory %>\wget.ps1' '%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%' '%LOCAL_DESTINATION_MSI_PATH%'"
95
+
96
+ if NOT ERRORLEVEL 1 (
97
+ echo Download succeeded
98
+ ) else (
99
+ echo Failed to download "%REMOTE_SOURCE_MSI_URL%"
100
+ echo Subsequent attempt to install the downloaded MSI is likely to fail
101
+ )
102
+ )
103
+
104
+ <%= install_chef %>
105
+
106
+ @endlocal
107
+
108
+ > <%= bootstrap_directory %>\validation.pem (
109
+ <%= validation_key %>
110
+ )
111
+
112
+ <% if @config[:encrypted_data_bag_secret] -%>
113
+ > <%= bootstrap_directory %>\encrypted_data_bag_secret (
114
+ <%= encrypted_data_bag_secret %>
115
+ )
116
+ <% end -%>
117
+
118
+ > <%= bootstrap_directory %>\client.rb (
119
+ <%= config_content %>
120
+ )
121
+
122
+ > <%= bootstrap_directory %>\first-boot.json (
123
+ <%= run_list %>
124
+ )
125
+
126
+ <%= start_chef %>
127
+
@@ -0,0 +1,68 @@
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
+ <%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
20
+ mkdir C:\chef
21
+
22
+ > C:\chef\wget.vbs (
23
+ <%= win_wget %>
24
+ )
25
+
26
+ cscript /nologo C:\chef\wget.vbs /url:http://files.rubyforge.vm.bytemark.co.uk/rubyinstaller/rubyinstaller-1.8.7-p334.exe /path:%TEMP%\rubyinstaller.exe
27
+ %TEMP%\rubyinstaller.exe /verysilent /dir="C:\ruby" /tasks="assocfiles,modpath"
28
+
29
+ @rem Install the Ruby Dev Kit so we compile us some native gems
30
+ cscript /nologo C:\chef\wget.vbs /url:http://cloud.github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe /path:%TEMP%\rubydevkit.exe
31
+ mkdir C:\DevKit
32
+ copy %TEMP%\rubydevkit.exe C:\DevKit
33
+ cmd.exe /C C:\DevKit\rubydevkit.exe -y
34
+
35
+ @rem update path during bootstrap session
36
+ SET PATH=%PATH%;C:\ruby\bin
37
+
38
+ cmd.exe /C ruby c:/DevKit/dk.rb init
39
+ cmd.exe /C ruby c:/DevKit/dk.rb install
40
+
41
+ cmd.exe /C gem install win32-api win32-service --platform=mswin32
42
+ cmd.exe /C gem install win32-open3 rdp-ruby-wmi windows-api windows-pr --no-rdoc --no-ri --verbose
43
+
44
+ @rem Install Chef gems separately to prevent 'failed to allocate memory' errors
45
+ cmd.exe /C gem install ohai --no-rdoc --no-ri --verbose
46
+ cmd.exe /C gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
47
+
48
+ > C:\chef\validation.pem (
49
+ <%= validation_key %>
50
+ )
51
+
52
+ <% if @config[:encrypted_data_bag_secret] -%>
53
+ > C:\chef\encrypted_data_bag_secret (
54
+ <%= encrypted_data_bag_secret %>
55
+ )
56
+ <% end -%>
57
+
58
+ > C:\chef\client.rb (
59
+ echo.require 'win32ole'
60
+ echo.WIN32OLE.codepage = WIN32OLE::CP_UTF8
61
+ <%= config_content %>
62
+ )
63
+
64
+ > C:\chef\first-boot.json (
65
+ <%= run_list %>
66
+ )
67
+
68
+ <%= start_chef %>