knife-windows 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
data/knife-windows.gemspec
CHANGED
@@ -15,8 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.description = s.summary
|
16
16
|
|
17
17
|
s.required_ruby_version = ">= 1.9.1"
|
18
|
-
s.add_dependency "
|
19
|
-
s.add_dependency "em-winrm", "= 0.0.4"
|
18
|
+
s.add_dependency "em-winrm", "= 0.0.5"
|
20
19
|
|
21
20
|
s.files = `git ls-files`.split("\n")
|
22
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -19,25 +19,7 @@
|
|
19
19
|
mkdir C:\chef
|
20
20
|
|
21
21
|
> C:\chef\wget.vbs (
|
22
|
-
|
23
|
-
echo.strHDLocation = WScript.Arguments.Item^(1^)
|
24
|
-
echo.Set objXMLHTTP = CreateObject^("MSXML2.XMLHTTP"^)
|
25
|
-
echo.objXMLHTTP.open "GET", strFileURL, false
|
26
|
-
echo.objXMLHTTP.send^(^)
|
27
|
-
echo.If objXMLHTTP.Status = 200 Then
|
28
|
-
echo.Set objADOStream = CreateObject^("ADODB.Stream"^)
|
29
|
-
echo.objADOStream.Open
|
30
|
-
echo.objADOStream.Type = 1
|
31
|
-
echo.objADOStream.Write objXMLHTTP.ResponseBody
|
32
|
-
echo.objADOStream.Position = 0
|
33
|
-
echo.Set objFSO = Createobject^("Scripting.FileSystemObject"^)
|
34
|
-
echo.If objFSO.Fileexists^(strHDLocation^) Then objFSO.DeleteFile strHDLocation
|
35
|
-
echo.Set objFSO = Nothing
|
36
|
-
echo.objADOStream.SaveToFile strHDLocation
|
37
|
-
echo.objADOStream.Close
|
38
|
-
echo.Set objADOStream = Nothing
|
39
|
-
echo.End if
|
40
|
-
echo.Set objXMLHTTP = Nothing
|
22
|
+
<%= win_wget %>
|
41
23
|
)
|
42
24
|
|
43
25
|
cscript /nologo C:\chef\wget.vbs http://files.rubyforge.vm.bytemark.co.uk/rubyinstaller/rubyinstaller-1.8.7-p334.exe %TEMP%\rubyinstaller.exe
|
@@ -51,50 +33,24 @@ cmd.exe /C C:\DevKit\rubydevkit.exe -y
|
|
51
33
|
cmd.exe /C C:\ruby\bin\ruby c:/DevKit/dk.rb init
|
52
34
|
cmd.exe /C C:\ruby\bin\ruby c:/DevKit/dk.rb install
|
53
35
|
|
54
|
-
cmd.exe /C C:\ruby\bin\gem install win32-open3 ruby-wmi windows-api windows-pr --no-rdoc --no-ri --verbose
|
36
|
+
cmd.exe /C C:\ruby\bin\gem install win32-open3 rdp-ruby-wmi windows-api windows-pr --no-rdoc --no-ri --verbose
|
55
37
|
|
56
38
|
@rem Install Chef gems separately to prevent 'failed to allocate memory' errors
|
57
|
-
cmd.exe /C C:\ruby\bin\gem install ohai --no-rdoc --no-ri --verbose
|
58
|
-
cmd.exe /C C:\ruby\bin\gem install chef --no-rdoc --no-ri --verbose <%=
|
39
|
+
cmd.exe /C C:\ruby\bin\gem install ohai --no-rdoc --no-ri --verbose
|
40
|
+
cmd.exe /C C:\ruby\bin\gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
|
59
41
|
|
60
42
|
> C:\chef\validation.pem (
|
61
|
-
|
62
|
-
<%= "echo.#{line.strip}" %>
|
63
|
-
<% end -%>
|
64
|
-
echo.
|
43
|
+
<%= validation_key %>
|
65
44
|
)
|
66
45
|
|
67
46
|
> C:\chef\client.rb (
|
68
47
|
echo.require 'win32ole'
|
69
48
|
echo.WIN32OLE.codepage = WIN32OLE::CP_UTF8
|
70
|
-
|
71
|
-
echo.log_location STDOUT
|
72
|
-
echo.chef_server_url "<%= Chef::Config[:chef_server_url] %>"
|
73
|
-
echo.validation_client_name "<%= Chef::Config[:validation_client_name] %>"
|
74
|
-
echo.client_key "c:/chef/client.pem"
|
75
|
-
echo.validation_key "c:/chef/validation.pem"
|
76
|
-
echo.checksum_path "c:/chef/checksums"
|
77
|
-
echo.file_cache_path "c:/chef/cache"
|
78
|
-
echo.file_backup_path "c:/chef/backup"
|
79
|
-
echo.cache_options ^( {:path, "c:/chef/cache/checksums", :skip_expires, true} ^)
|
80
|
-
<% if Chef::Config[:http_proxy] != nil %>
|
81
|
-
echo.http_proxy "<%= Chef::Config[:http_proxy] %>"
|
82
|
-
<% end %>
|
83
|
-
<% if Chef::Config[:https_proxy] != nil %>
|
84
|
-
echo.https_proxy "<%= Chef::Config[:https_proxy] %>"
|
85
|
-
<% end %>
|
86
|
-
<% if Chef::Config[:no_proxy] != nil %>
|
87
|
-
echo.no_proxy "<%= Chef::Config[:no_proxy] %>"
|
88
|
-
<% end %>
|
89
|
-
<% if @config[:chef_node_name] == nil %>
|
90
|
-
echo.# Using default node name
|
91
|
-
<% else %>
|
92
|
-
echo.node_name "<%= @config[:chef_node_name] %>"
|
93
|
-
<% end %>
|
49
|
+
<%= config_content %>
|
94
50
|
)
|
95
51
|
|
96
52
|
> C:\chef\first-boot.json (
|
97
|
-
|
53
|
+
<%= run_list %>
|
98
54
|
)
|
99
55
|
|
100
|
-
|
56
|
+
<%= start_chef %>
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife/core/bootstrap_context'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
module Core
|
24
|
+
# Instances of BootstrapContext are the context objects (i.e., +self+) for
|
25
|
+
# bootstrap templates. For backwards compatability, they +must+ set the
|
26
|
+
# following instance variables:
|
27
|
+
# * @config - a hash of knife's config values
|
28
|
+
# * @run_list - the run list for the node to boostrap
|
29
|
+
#
|
30
|
+
class WindowsBootstrapContext < BootstrapContext
|
31
|
+
|
32
|
+
def initialize(config, run_list, chef_config)
|
33
|
+
@config = config
|
34
|
+
@run_list = run_list
|
35
|
+
@chef_config = chef_config
|
36
|
+
super(config, run_list, chef_config)
|
37
|
+
end
|
38
|
+
|
39
|
+
def validation_key
|
40
|
+
val_key = escape_and_echo(super)
|
41
|
+
val_key << 'echo.'
|
42
|
+
end
|
43
|
+
|
44
|
+
def config_content
|
45
|
+
client_rb = <<-CONFIG
|
46
|
+
log_level :info
|
47
|
+
log_location STDOUT
|
48
|
+
chef_server_url "#{@chef_config[:chef_server_url]}"
|
49
|
+
validation_client_name "#{@chef_config[:validation_client_name]}"
|
50
|
+
|
51
|
+
client_key "c:/chef/client.pem"
|
52
|
+
validation_key "c:/chef/validation.pem"
|
53
|
+
checksum_path "c:/chef/checksums"
|
54
|
+
file_cache_path "c:/chef/cache"
|
55
|
+
file_backup_path "c:/chef/backup"
|
56
|
+
cache_options ( {:path => "c:/chef/cache/checksums", :skip_expires => true} )
|
57
|
+
|
58
|
+
CONFIG
|
59
|
+
if @config[:chef_node_name]
|
60
|
+
client_rb << %Q{node_name "#{@config[:chef_node_name]}"\n}
|
61
|
+
else
|
62
|
+
client_rb << "# Using default node name (fqdn)\n"
|
63
|
+
end
|
64
|
+
escape_and_echo(client_rb)
|
65
|
+
end
|
66
|
+
|
67
|
+
def start_chef
|
68
|
+
"c:/ruby/bin/ruby c:/ruby/bin/chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json -E #{bootstrap_environment}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def run_list
|
72
|
+
escape_and_echo({ "run_list" => @run_list }.to_json)
|
73
|
+
end
|
74
|
+
|
75
|
+
def win_wget
|
76
|
+
win_wget = <<-WGET
|
77
|
+
strFileUrl = WScript.Arguments.Item(0)
|
78
|
+
strHDLocation = WScript.Arguments.Item(1)
|
79
|
+
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
|
80
|
+
objXMLHTTP.open "GET", strFileURL, false
|
81
|
+
objXMLHTTP.send()
|
82
|
+
If objXMLHTTP.Status = 200 Then
|
83
|
+
Set objADOStream = CreateObject("ADODB.Stream")
|
84
|
+
objADOStream.Open
|
85
|
+
objADOStream.Type = 1
|
86
|
+
objADOStream.Write objXMLHTTP.ResponseBody
|
87
|
+
objADOStream.Position = 0
|
88
|
+
Set objFSO = Createobject("Scripting.FileSystemObject")
|
89
|
+
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
|
90
|
+
Set objFSO = Nothing
|
91
|
+
objADOStream.SaveToFile strHDLocation
|
92
|
+
objADOStream.Close
|
93
|
+
Set objADOStream = Nothing
|
94
|
+
End if
|
95
|
+
Set objXMLHTTP = Nothing
|
96
|
+
WGET
|
97
|
+
escape_and_echo(win_wget)
|
98
|
+
end
|
99
|
+
|
100
|
+
# escape WIN BATCH special chars
|
101
|
+
# and prefixes each line with an
|
102
|
+
# echo
|
103
|
+
def escape_and_echo(file_contents)
|
104
|
+
file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -17,18 +17,20 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
|
+
require 'erubis'
|
20
21
|
|
21
22
|
class Chef
|
22
23
|
class Knife
|
23
|
-
class WinrmBootstrap <
|
24
|
+
class WinrmBootstrap < Bootstrap
|
24
25
|
|
25
26
|
deps do
|
27
|
+
require 'chef/knife/core/windows_bootstrap_context'
|
26
28
|
require 'chef/json_compat'
|
27
29
|
require 'tempfile'
|
28
|
-
|
30
|
+
Chef::Knife::Winrm.load_deps
|
29
31
|
end
|
30
32
|
|
31
|
-
banner "knife winrm bootstrap FQDN
|
33
|
+
banner "knife winrm bootstrap FQDN (options)"
|
32
34
|
|
33
35
|
option :winrm_user,
|
34
36
|
:short => "-x USERNAME",
|
@@ -90,6 +92,11 @@ class Chef
|
|
90
92
|
:long => "--prerelease",
|
91
93
|
:description => "Install the pre-release chef gems"
|
92
94
|
|
95
|
+
option :bootstrap_version,
|
96
|
+
:long => "--bootstrap-version VERSION",
|
97
|
+
:description => "The version of Chef to install",
|
98
|
+
:proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
|
99
|
+
|
93
100
|
option :distro,
|
94
101
|
:short => "-d DISTRO",
|
95
102
|
:long => "--distro DISTRO",
|
@@ -108,6 +115,7 @@ class Chef
|
|
108
115
|
:proc => lambda { |o| o.split(",") },
|
109
116
|
:default => []
|
110
117
|
|
118
|
+
# TODO: This should go away when CHEF-2193 is fixed
|
111
119
|
def load_template(template=nil)
|
112
120
|
# Are we bootstrapping using an already shipped template?
|
113
121
|
if config[:template_file]
|
@@ -136,9 +144,7 @@ class Chef
|
|
136
144
|
end
|
137
145
|
|
138
146
|
def render_template(template=nil)
|
139
|
-
context =
|
140
|
-
context[:run_list] = config[:run_list]
|
141
|
-
context[:config] = config
|
147
|
+
context = Knife::Core::WindowsBootstrapContext.new(config, config[:run_list], Chef::Config)
|
142
148
|
Erubis::Eruby.new(template).evaluate(context)
|
143
149
|
end
|
144
150
|
|
@@ -163,16 +169,16 @@ class Chef
|
|
163
169
|
knife_winrm(bootstrap_command).run
|
164
170
|
end
|
165
171
|
|
166
|
-
def validate_name_args!
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
def server_name
|
174
|
-
|
175
|
-
end
|
172
|
+
# def validate_name_args!
|
173
|
+
# if Array(@name_args).first.nil?
|
174
|
+
# ui.error("Must pass an FQDN or ip to bootstrap")
|
175
|
+
# exit 1
|
176
|
+
# end
|
177
|
+
# end
|
178
|
+
#
|
179
|
+
# def server_name
|
180
|
+
# Array(@name_args).first
|
181
|
+
# end
|
176
182
|
|
177
183
|
def knife_winrm(command = '')
|
178
184
|
winrm = Chef::Knife::Winrm.new
|
@@ -185,7 +191,7 @@ class Chef
|
|
185
191
|
winrm.config[:kerberos_service] = Chef::Config[:knife][:kerberos_service] if Chef::Config[:knife][:kerberos_service]
|
186
192
|
winrm.config[:ca_trust_file] = Chef::Config[:knife][:ca_trust_file] if Chef::Config[:knife][:ca_trust_file]
|
187
193
|
winrm.config[:manual] = true
|
188
|
-
winrm.config[:winrm_port] = Chef::Config[:knife][:winrm_port]
|
194
|
+
winrm.config[:winrm_port] = Chef::Config[:knife][:winrm_port] || config[:winrm_port]
|
189
195
|
winrm
|
190
196
|
end
|
191
197
|
|
@@ -212,6 +218,7 @@ class Chef
|
|
212
218
|
def bootstrap_bat_file
|
213
219
|
"%TEMP%\\bootstrap.bat"
|
214
220
|
end
|
221
|
+
|
215
222
|
end
|
216
223
|
end
|
217
224
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: knife-windows
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.5.
|
5
|
+
version: 0.5.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Seth Chisamore
|
@@ -10,31 +10,20 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-29 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name: chef
|
18
|
-
prerelease: false
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
-
none: false
|
21
|
-
requirements:
|
22
|
-
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.10.0.beta.5
|
25
|
-
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
16
|
- !ruby/object:Gem::Dependency
|
28
17
|
name: em-winrm
|
29
18
|
prerelease: false
|
30
|
-
requirement: &
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
31
20
|
none: false
|
32
21
|
requirements:
|
33
22
|
- - "="
|
34
23
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.0.
|
24
|
+
version: 0.0.5
|
36
25
|
type: :runtime
|
37
|
-
version_requirements: *
|
26
|
+
version_requirements: *id001
|
38
27
|
description: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting with nodes running Microsoft Windows
|
39
28
|
email:
|
40
29
|
- schisamo@opscode.com
|
@@ -53,6 +42,7 @@ files:
|
|
53
42
|
- Rakefile
|
54
43
|
- knife-windows.gemspec
|
55
44
|
- lib/chef/knife/bootstrap/windows-shell.erb
|
45
|
+
- lib/chef/knife/core/windows_bootstrap_context.rb
|
56
46
|
- lib/chef/knife/winrm.rb
|
57
47
|
- lib/chef/knife/winrm_bootstrap.rb
|
58
48
|
- lib/knife-windows/version.rb
|