knife-windows 0.5.15 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +4 -4
- data/.rspec +3 -3
- data/.travis.yml +6 -6
- data/CHANGELOG.md +33 -0
- data/DOC_CHANGES.md +42 -0
- data/Gemfile +11 -11
- data/LICENSE +201 -201
- data/README.rdoc +134 -140
- data/RELEASE_NOTES.md +40 -0
- data/Rakefile +16 -16
- data/features/knife_help.feature +20 -20
- data/features/support/env.rb +5 -5
- data/knife-windows.gemspec +24 -24
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +222 -222
- data/lib/chef/knife/bootstrap_windows_base.rb +206 -196
- data/lib/chef/knife/bootstrap_windows_ssh.rb +93 -93
- data/lib/chef/knife/bootstrap_windows_winrm.rb +97 -62
- data/lib/chef/knife/core/windows_bootstrap_context.rb +177 -177
- data/lib/chef/knife/windows_helper.rb +34 -34
- data/lib/chef/knife/winrm.rb +296 -286
- data/lib/chef/knife/winrm_base.rb +99 -99
- data/lib/knife-windows/version.rb +6 -6
- data/spec/functional/bootstrap_download_spec.rb +122 -120
- data/spec/spec_helper.rb +63 -63
- data/spec/unit/knife/bootstrap_template_spec.rb +91 -91
- data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +85 -0
- data/spec/unit/knife/winrm_spec.rb +152 -82
- metadata +17 -12
- data/CHANGELOG +0 -14
- data/lib/chef/knife/bootstrap/windows-shell.erb +0 -68
@@ -1,93 +1,93 @@
|
|
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/bootstrap_windows_base'
|
20
|
-
|
21
|
-
class Chef
|
22
|
-
class Knife
|
23
|
-
class BootstrapWindowsSsh < Bootstrap
|
24
|
-
|
25
|
-
include Chef::Knife::BootstrapWindowsBase
|
26
|
-
|
27
|
-
deps do
|
28
|
-
require 'chef/knife/core/windows_bootstrap_context'
|
29
|
-
require 'chef/json_compat'
|
30
|
-
require 'tempfile'
|
31
|
-
require 'highline'
|
32
|
-
require 'net/ssh'
|
33
|
-
require 'net/ssh/multi'
|
34
|
-
Chef::Knife::Ssh.load_deps
|
35
|
-
end
|
36
|
-
|
37
|
-
banner "knife bootstrap windows ssh FQDN (options)"
|
38
|
-
|
39
|
-
option :ssh_user,
|
40
|
-
:short => "-x USERNAME",
|
41
|
-
:long => "--ssh-user USERNAME",
|
42
|
-
:description => "The ssh username",
|
43
|
-
:default => "root"
|
44
|
-
|
45
|
-
option :ssh_password,
|
46
|
-
:short => "-P PASSWORD",
|
47
|
-
:long => "--ssh-password PASSWORD",
|
48
|
-
:description => "The ssh password"
|
49
|
-
|
50
|
-
option :ssh_port,
|
51
|
-
:short => "-p PORT",
|
52
|
-
:long => "--ssh-port PORT",
|
53
|
-
:description => "The ssh port",
|
54
|
-
:default => "22",
|
55
|
-
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
|
56
|
-
|
57
|
-
option :ssh_gateway,
|
58
|
-
:short => "-G GATEWAY",
|
59
|
-
:long => "--ssh-gateway GATEWAY",
|
60
|
-
:description => "The ssh gateway",
|
61
|
-
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key }
|
62
|
-
|
63
|
-
option :identity_file,
|
64
|
-
:short => "-i IDENTITY_FILE",
|
65
|
-
:long => "--identity-file IDENTITY_FILE",
|
66
|
-
:description => "The SSH identity file used for authentication"
|
67
|
-
|
68
|
-
option :host_key_verification,
|
69
|
-
:long => "--[no-]host-key-verification",
|
70
|
-
:description => "Disable host key verification",
|
71
|
-
:boolean => true,
|
72
|
-
:default => true
|
73
|
-
|
74
|
-
def run
|
75
|
-
bootstrap
|
76
|
-
end
|
77
|
-
|
78
|
-
def run_command(command = '')
|
79
|
-
ssh = Chef::Knife::Ssh.new
|
80
|
-
ssh.name_args = [ server_name, command ]
|
81
|
-
ssh.config[:ssh_user] = locate_config_value(:ssh_user)
|
82
|
-
ssh.config[:ssh_password] = locate_config_value(:ssh_password)
|
83
|
-
ssh.config[:ssh_port] = locate_config_value(:ssh_port)
|
84
|
-
ssh.config[:ssh_gateway] = locate_config_value(:ssh_gateway)
|
85
|
-
ssh.config[:identity_file] = config[:identity_file]
|
86
|
-
ssh.config[:manual] = true
|
87
|
-
ssh.config[:host_key_verify] = config[:host_key_verify]
|
88
|
-
ssh.run
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
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/bootstrap_windows_base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class BootstrapWindowsSsh < Bootstrap
|
24
|
+
|
25
|
+
include Chef::Knife::BootstrapWindowsBase
|
26
|
+
|
27
|
+
deps do
|
28
|
+
require 'chef/knife/core/windows_bootstrap_context'
|
29
|
+
require 'chef/json_compat'
|
30
|
+
require 'tempfile'
|
31
|
+
require 'highline'
|
32
|
+
require 'net/ssh'
|
33
|
+
require 'net/ssh/multi'
|
34
|
+
Chef::Knife::Ssh.load_deps
|
35
|
+
end
|
36
|
+
|
37
|
+
banner "knife bootstrap windows ssh FQDN (options)"
|
38
|
+
|
39
|
+
option :ssh_user,
|
40
|
+
:short => "-x USERNAME",
|
41
|
+
:long => "--ssh-user USERNAME",
|
42
|
+
:description => "The ssh username",
|
43
|
+
:default => "root"
|
44
|
+
|
45
|
+
option :ssh_password,
|
46
|
+
:short => "-P PASSWORD",
|
47
|
+
:long => "--ssh-password PASSWORD",
|
48
|
+
:description => "The ssh password"
|
49
|
+
|
50
|
+
option :ssh_port,
|
51
|
+
:short => "-p PORT",
|
52
|
+
:long => "--ssh-port PORT",
|
53
|
+
:description => "The ssh port",
|
54
|
+
:default => "22",
|
55
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
|
56
|
+
|
57
|
+
option :ssh_gateway,
|
58
|
+
:short => "-G GATEWAY",
|
59
|
+
:long => "--ssh-gateway GATEWAY",
|
60
|
+
:description => "The ssh gateway",
|
61
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key }
|
62
|
+
|
63
|
+
option :identity_file,
|
64
|
+
:short => "-i IDENTITY_FILE",
|
65
|
+
:long => "--identity-file IDENTITY_FILE",
|
66
|
+
:description => "The SSH identity file used for authentication"
|
67
|
+
|
68
|
+
option :host_key_verification,
|
69
|
+
:long => "--[no-]host-key-verification",
|
70
|
+
:description => "Disable host key verification",
|
71
|
+
:boolean => true,
|
72
|
+
:default => true
|
73
|
+
|
74
|
+
def run
|
75
|
+
bootstrap
|
76
|
+
end
|
77
|
+
|
78
|
+
def run_command(command = '')
|
79
|
+
ssh = Chef::Knife::Ssh.new
|
80
|
+
ssh.name_args = [ server_name, command ]
|
81
|
+
ssh.config[:ssh_user] = locate_config_value(:ssh_user)
|
82
|
+
ssh.config[:ssh_password] = locate_config_value(:ssh_password)
|
83
|
+
ssh.config[:ssh_port] = locate_config_value(:ssh_port)
|
84
|
+
ssh.config[:ssh_gateway] = locate_config_value(:ssh_gateway)
|
85
|
+
ssh.config[:identity_file] = config[:identity_file]
|
86
|
+
ssh.config[:manual] = true
|
87
|
+
ssh.config[:host_key_verify] = config[:host_key_verify]
|
88
|
+
ssh.run
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -1,62 +1,97 @@
|
|
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/bootstrap_windows_base'
|
20
|
-
require 'chef/knife/winrm'
|
21
|
-
require 'chef/knife/winrm_base'
|
22
|
-
require 'chef/knife/bootstrap'
|
23
|
-
|
24
|
-
class Chef
|
25
|
-
class Knife
|
26
|
-
class BootstrapWindowsWinrm < Bootstrap
|
27
|
-
|
28
|
-
include Chef::Knife::BootstrapWindowsBase
|
29
|
-
include Chef::Knife::WinrmBase
|
30
|
-
|
31
|
-
deps do
|
32
|
-
require 'chef/knife/core/windows_bootstrap_context'
|
33
|
-
require 'chef/json_compat'
|
34
|
-
require 'tempfile'
|
35
|
-
Chef::Knife::Winrm.load_deps
|
36
|
-
end
|
37
|
-
|
38
|
-
banner "knife bootstrap windows winrm FQDN (options)"
|
39
|
-
|
40
|
-
def run
|
41
|
-
bootstrap
|
42
|
-
end
|
43
|
-
|
44
|
-
def run_command(command = '')
|
45
|
-
winrm = Chef::Knife::Winrm.new
|
46
|
-
winrm.name_args = [ server_name, command ]
|
47
|
-
winrm.config[:winrm_user] = locate_config_value(:winrm_user)
|
48
|
-
winrm.config[:winrm_password] = locate_config_value(:winrm_password)
|
49
|
-
winrm.config[:winrm_transport] = locate_config_value(:winrm_transport)
|
50
|
-
winrm.config[:kerberos_keytab_file] = Chef::Config[:knife][:kerberos_keytab_file] if Chef::Config[:knife][:kerberos_keytab_file]
|
51
|
-
winrm.config[:kerberos_realm] = Chef::Config[:knife][:kerberos_realm] if Chef::Config[:knife][:kerberos_realm]
|
52
|
-
winrm.config[:kerberos_service] = Chef::Config[:knife][:kerberos_service] if Chef::Config[:knife][:kerberos_service]
|
53
|
-
winrm.config[:ca_trust_file] = Chef::Config[:knife][:ca_trust_file] if Chef::Config[:knife][:ca_trust_file]
|
54
|
-
winrm.config[:manual] = true
|
55
|
-
winrm.config[:winrm_port] = locate_config_value(:winrm_port)
|
56
|
-
winrm.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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/bootstrap_windows_base'
|
20
|
+
require 'chef/knife/winrm'
|
21
|
+
require 'chef/knife/winrm_base'
|
22
|
+
require 'chef/knife/bootstrap'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Knife
|
26
|
+
class BootstrapWindowsWinrm < Bootstrap
|
27
|
+
|
28
|
+
include Chef::Knife::BootstrapWindowsBase
|
29
|
+
include Chef::Knife::WinrmBase
|
30
|
+
|
31
|
+
deps do
|
32
|
+
require 'chef/knife/core/windows_bootstrap_context'
|
33
|
+
require 'chef/json_compat'
|
34
|
+
require 'tempfile'
|
35
|
+
Chef::Knife::Winrm.load_deps
|
36
|
+
end
|
37
|
+
|
38
|
+
banner "knife bootstrap windows winrm FQDN (options)"
|
39
|
+
|
40
|
+
def run
|
41
|
+
bootstrap
|
42
|
+
end
|
43
|
+
|
44
|
+
def run_command(command = '')
|
45
|
+
winrm = Chef::Knife::Winrm.new
|
46
|
+
winrm.name_args = [ server_name, command ]
|
47
|
+
winrm.config[:winrm_user] = locate_config_value(:winrm_user)
|
48
|
+
winrm.config[:winrm_password] = locate_config_value(:winrm_password)
|
49
|
+
winrm.config[:winrm_transport] = locate_config_value(:winrm_transport)
|
50
|
+
winrm.config[:kerberos_keytab_file] = Chef::Config[:knife][:kerberos_keytab_file] if Chef::Config[:knife][:kerberos_keytab_file]
|
51
|
+
winrm.config[:kerberos_realm] = Chef::Config[:knife][:kerberos_realm] if Chef::Config[:knife][:kerberos_realm]
|
52
|
+
winrm.config[:kerberos_service] = Chef::Config[:knife][:kerberos_service] if Chef::Config[:knife][:kerberos_service]
|
53
|
+
winrm.config[:ca_trust_file] = Chef::Config[:knife][:ca_trust_file] if Chef::Config[:knife][:ca_trust_file]
|
54
|
+
winrm.config[:manual] = true
|
55
|
+
winrm.config[:winrm_port] = locate_config_value(:winrm_port)
|
56
|
+
winrm.config[:suppress_auth_failure] = true
|
57
|
+
winrm.config[:returns] = nil
|
58
|
+
winrm.run
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def wait_for_remote_response(wait_max_minutes)
|
64
|
+
wait_max_seconds = wait_max_minutes * 60
|
65
|
+
retry_interval_seconds = 10
|
66
|
+
retries_left = wait_max_seconds / retry_interval_seconds
|
67
|
+
print(ui.color("\nWaiting for remote response before bootstrap", :magenta))
|
68
|
+
wait_start_time = Time.now
|
69
|
+
begin
|
70
|
+
print(".")
|
71
|
+
# Return status of the command is non-zero, typically nil,
|
72
|
+
# for our simple echo command in cases where run_command
|
73
|
+
# swallows the exception, such as 401's. Treat such cases
|
74
|
+
# the same as the case where we encounter an exception.
|
75
|
+
status = run_command("echo . & echo Response received.")
|
76
|
+
raise RuntimeError, 'Command execution failed.' if status != 0
|
77
|
+
ui.info(ui.color("Remote node responded after #{elapsed_time_in_minutes(wait_start_time)} minutes.", :magenta))
|
78
|
+
return
|
79
|
+
rescue
|
80
|
+
retries_left -= 1
|
81
|
+
if retries_left <= 0 || (elapsed_time_in_minutes(wait_start_time) > wait_max_minutes)
|
82
|
+
ui.error("No response received from remote node after #{elapsed_time_in_minutes(wait_start_time)} minutes, giving up.")
|
83
|
+
raise
|
84
|
+
end
|
85
|
+
print '.'
|
86
|
+
sleep retry_interval_seconds
|
87
|
+
retry
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def elapsed_time_in_minutes(start_time)
|
92
|
+
((Time.now - start_time) / 60).round(2)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -1,177 +1,177 @@
|
|
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
|
-
escape_and_echo(super)
|
41
|
-
end
|
42
|
-
|
43
|
-
def encrypted_data_bag_secret
|
44
|
-
escape_and_echo(@config[:encrypted_data_bag_secret])
|
45
|
-
end
|
46
|
-
|
47
|
-
def config_content
|
48
|
-
client_rb = <<-CONFIG
|
49
|
-
log_level :info
|
50
|
-
log_location STDOUT
|
51
|
-
|
52
|
-
chef_server_url "#{@chef_config[:chef_server_url]}"
|
53
|
-
validation_client_name "#{@chef_config[:validation_client_name]}"
|
54
|
-
client_key "c:/chef/client.pem"
|
55
|
-
validation_key "c:/chef/validation.pem"
|
56
|
-
|
57
|
-
file_cache_path "c:/chef/cache"
|
58
|
-
file_backup_path "c:/chef/backup"
|
59
|
-
cache_options ({:path => "c:/chef/cache/checksums", :skip_expires => true})
|
60
|
-
|
61
|
-
CONFIG
|
62
|
-
if @config[:chef_node_name]
|
63
|
-
client_rb << %Q{node_name "#{@config[:chef_node_name]}"\n}
|
64
|
-
else
|
65
|
-
client_rb << "# Using default node name (fqdn)\n"
|
66
|
-
end
|
67
|
-
|
68
|
-
if knife_config[:bootstrap_proxy]
|
69
|
-
client_rb << "\n"
|
70
|
-
client_rb << %Q{http_proxy "#{knife_config[:bootstrap_proxy]}"\n}
|
71
|
-
client_rb << %Q{https_proxy "#{knife_config[:bootstrap_proxy]}"\n}
|
72
|
-
client_rb << %Q{no_proxy "#{knife_config[:bootstrap_no_proxy]}"\n} if knife_config[:bootstrap_no_proxy]
|
73
|
-
end
|
74
|
-
|
75
|
-
if @config[:encrypted_data_bag_secret]
|
76
|
-
client_rb << %Q{encrypted_data_bag_secret "c:/chef/encrypted_data_bag_secret"\n}
|
77
|
-
end
|
78
|
-
|
79
|
-
escape_and_echo(client_rb)
|
80
|
-
end
|
81
|
-
|
82
|
-
def start_chef
|
83
|
-
start_chef = "SET \"PATH=%PATH%;C:\\ruby\\bin;C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin\"\n"
|
84
|
-
start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json -E #{bootstrap_environment}\n"
|
85
|
-
end
|
86
|
-
|
87
|
-
def win_wget
|
88
|
-
win_wget = <<-WGET
|
89
|
-
url = WScript.Arguments.Named("url")
|
90
|
-
path = WScript.Arguments.Named("path")
|
91
|
-
proxy = null
|
92
|
-
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
|
93
|
-
Set wshShell = CreateObject( "WScript.Shell" )
|
94
|
-
Set objUserVariables = wshShell.Environment("USER")
|
95
|
-
|
96
|
-
rem http proxy is optional
|
97
|
-
rem attempt to read from HTTP_PROXY env var first
|
98
|
-
On Error Resume Next
|
99
|
-
|
100
|
-
If NOT (objUserVariables("HTTP_PROXY") = "") Then
|
101
|
-
proxy = objUserVariables("HTTP_PROXY")
|
102
|
-
|
103
|
-
rem fall back to named arg
|
104
|
-
ElseIf NOT (WScript.Arguments.Named("proxy") = "") Then
|
105
|
-
proxy = WScript.Arguments.Named("proxy")
|
106
|
-
End If
|
107
|
-
|
108
|
-
If NOT isNull(proxy) Then
|
109
|
-
rem setProxy method is only available on ServerXMLHTTP 6.0+
|
110
|
-
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
|
111
|
-
objXMLHTTP.setProxy 2, proxy
|
112
|
-
End If
|
113
|
-
|
114
|
-
On Error Goto 0
|
115
|
-
|
116
|
-
objXMLHTTP.open "GET", url, false
|
117
|
-
objXMLHTTP.send()
|
118
|
-
If objXMLHTTP.Status = 200 Then
|
119
|
-
Set objADOStream = CreateObject("ADODB.Stream")
|
120
|
-
objADOStream.Open
|
121
|
-
objADOStream.Type = 1
|
122
|
-
objADOStream.Write objXMLHTTP.ResponseBody
|
123
|
-
objADOStream.Position = 0
|
124
|
-
Set objFSO = Createobject("Scripting.FileSystemObject")
|
125
|
-
If objFSO.Fileexists(path) Then objFSO.DeleteFile path
|
126
|
-
Set objFSO = Nothing
|
127
|
-
objADOStream.SaveToFile path
|
128
|
-
objADOStream.Close
|
129
|
-
Set objADOStream = Nothing
|
130
|
-
End if
|
131
|
-
Set objXMLHTTP = Nothing
|
132
|
-
WGET
|
133
|
-
escape_and_echo(win_wget)
|
134
|
-
end
|
135
|
-
|
136
|
-
def win_wget_ps
|
137
|
-
win_wget_ps = <<-WGET_PS
|
138
|
-
param(
|
139
|
-
[String] $remoteUrl,
|
140
|
-
[String] $localPath
|
141
|
-
)
|
142
|
-
|
143
|
-
$webClient = new-object System.Net.WebClient;
|
144
|
-
|
145
|
-
$webClient.DownloadFile($remoteUrl, $localPath);
|
146
|
-
WGET_PS
|
147
|
-
|
148
|
-
escape_and_echo(win_wget_ps)
|
149
|
-
end
|
150
|
-
|
151
|
-
def install_chef
|
152
|
-
install_chef = 'msiexec /qn /log "%CHEF_CLIENT_MSI_LOG_PATH%" /i "%LOCAL_DESTINATION_MSI_PATH%"'
|
153
|
-
end
|
154
|
-
|
155
|
-
def bootstrap_directory
|
156
|
-
bootstrap_directory = "C:\\chef"
|
157
|
-
end
|
158
|
-
|
159
|
-
def local_download_path
|
160
|
-
local_download_path = "%TEMP%\\chef-client-latest.msi"
|
161
|
-
end
|
162
|
-
|
163
|
-
def first_boot
|
164
|
-
first_boot_attributes_and_run_list = (@config[:first_boot_attributes] || {}).merge(:run_list => @run_list)
|
165
|
-
escape_and_echo(first_boot_attributes_and_run_list.to_json)
|
166
|
-
end
|
167
|
-
|
168
|
-
# escape WIN BATCH special chars
|
169
|
-
# and prefixes each line with an
|
170
|
-
# echo
|
171
|
-
def escape_and_echo(file_contents)
|
172
|
-
file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
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
|
+
escape_and_echo(super)
|
41
|
+
end
|
42
|
+
|
43
|
+
def encrypted_data_bag_secret
|
44
|
+
escape_and_echo(@config[:encrypted_data_bag_secret])
|
45
|
+
end
|
46
|
+
|
47
|
+
def config_content
|
48
|
+
client_rb = <<-CONFIG
|
49
|
+
log_level :info
|
50
|
+
log_location STDOUT
|
51
|
+
|
52
|
+
chef_server_url "#{@chef_config[:chef_server_url]}"
|
53
|
+
validation_client_name "#{@chef_config[:validation_client_name]}"
|
54
|
+
client_key "c:/chef/client.pem"
|
55
|
+
validation_key "c:/chef/validation.pem"
|
56
|
+
|
57
|
+
file_cache_path "c:/chef/cache"
|
58
|
+
file_backup_path "c:/chef/backup"
|
59
|
+
cache_options ({:path => "c:/chef/cache/checksums", :skip_expires => true})
|
60
|
+
|
61
|
+
CONFIG
|
62
|
+
if @config[:chef_node_name]
|
63
|
+
client_rb << %Q{node_name "#{@config[:chef_node_name]}"\n}
|
64
|
+
else
|
65
|
+
client_rb << "# Using default node name (fqdn)\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
if knife_config[:bootstrap_proxy]
|
69
|
+
client_rb << "\n"
|
70
|
+
client_rb << %Q{http_proxy "#{knife_config[:bootstrap_proxy]}"\n}
|
71
|
+
client_rb << %Q{https_proxy "#{knife_config[:bootstrap_proxy]}"\n}
|
72
|
+
client_rb << %Q{no_proxy "#{knife_config[:bootstrap_no_proxy]}"\n} if knife_config[:bootstrap_no_proxy]
|
73
|
+
end
|
74
|
+
|
75
|
+
if @config[:encrypted_data_bag_secret]
|
76
|
+
client_rb << %Q{encrypted_data_bag_secret "c:/chef/encrypted_data_bag_secret"\n}
|
77
|
+
end
|
78
|
+
|
79
|
+
escape_and_echo(client_rb)
|
80
|
+
end
|
81
|
+
|
82
|
+
def start_chef
|
83
|
+
start_chef = "SET \"PATH=%PATH%;C:\\ruby\\bin;C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin\"\n"
|
84
|
+
start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json -E #{bootstrap_environment}\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
def win_wget
|
88
|
+
win_wget = <<-WGET
|
89
|
+
url = WScript.Arguments.Named("url")
|
90
|
+
path = WScript.Arguments.Named("path")
|
91
|
+
proxy = null
|
92
|
+
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
|
93
|
+
Set wshShell = CreateObject( "WScript.Shell" )
|
94
|
+
Set objUserVariables = wshShell.Environment("USER")
|
95
|
+
|
96
|
+
rem http proxy is optional
|
97
|
+
rem attempt to read from HTTP_PROXY env var first
|
98
|
+
On Error Resume Next
|
99
|
+
|
100
|
+
If NOT (objUserVariables("HTTP_PROXY") = "") Then
|
101
|
+
proxy = objUserVariables("HTTP_PROXY")
|
102
|
+
|
103
|
+
rem fall back to named arg
|
104
|
+
ElseIf NOT (WScript.Arguments.Named("proxy") = "") Then
|
105
|
+
proxy = WScript.Arguments.Named("proxy")
|
106
|
+
End If
|
107
|
+
|
108
|
+
If NOT isNull(proxy) Then
|
109
|
+
rem setProxy method is only available on ServerXMLHTTP 6.0+
|
110
|
+
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
|
111
|
+
objXMLHTTP.setProxy 2, proxy
|
112
|
+
End If
|
113
|
+
|
114
|
+
On Error Goto 0
|
115
|
+
|
116
|
+
objXMLHTTP.open "GET", url, false
|
117
|
+
objXMLHTTP.send()
|
118
|
+
If objXMLHTTP.Status = 200 Then
|
119
|
+
Set objADOStream = CreateObject("ADODB.Stream")
|
120
|
+
objADOStream.Open
|
121
|
+
objADOStream.Type = 1
|
122
|
+
objADOStream.Write objXMLHTTP.ResponseBody
|
123
|
+
objADOStream.Position = 0
|
124
|
+
Set objFSO = Createobject("Scripting.FileSystemObject")
|
125
|
+
If objFSO.Fileexists(path) Then objFSO.DeleteFile path
|
126
|
+
Set objFSO = Nothing
|
127
|
+
objADOStream.SaveToFile path
|
128
|
+
objADOStream.Close
|
129
|
+
Set objADOStream = Nothing
|
130
|
+
End if
|
131
|
+
Set objXMLHTTP = Nothing
|
132
|
+
WGET
|
133
|
+
escape_and_echo(win_wget)
|
134
|
+
end
|
135
|
+
|
136
|
+
def win_wget_ps
|
137
|
+
win_wget_ps = <<-WGET_PS
|
138
|
+
param(
|
139
|
+
[String] $remoteUrl,
|
140
|
+
[String] $localPath
|
141
|
+
)
|
142
|
+
|
143
|
+
$webClient = new-object System.Net.WebClient;
|
144
|
+
|
145
|
+
$webClient.DownloadFile($remoteUrl, $localPath);
|
146
|
+
WGET_PS
|
147
|
+
|
148
|
+
escape_and_echo(win_wget_ps)
|
149
|
+
end
|
150
|
+
|
151
|
+
def install_chef
|
152
|
+
install_chef = 'msiexec /qn /log "%CHEF_CLIENT_MSI_LOG_PATH%" /i "%LOCAL_DESTINATION_MSI_PATH%"'
|
153
|
+
end
|
154
|
+
|
155
|
+
def bootstrap_directory
|
156
|
+
bootstrap_directory = "C:\\chef"
|
157
|
+
end
|
158
|
+
|
159
|
+
def local_download_path
|
160
|
+
local_download_path = "%TEMP%\\chef-client-latest.msi"
|
161
|
+
end
|
162
|
+
|
163
|
+
def first_boot
|
164
|
+
first_boot_attributes_and_run_list = (@config[:first_boot_attributes] || {}).merge(:run_list => @run_list)
|
165
|
+
escape_and_echo(first_boot_attributes_and_run_list.to_json)
|
166
|
+
end
|
167
|
+
|
168
|
+
# escape WIN BATCH special chars
|
169
|
+
# and prefixes each line with an
|
170
|
+
# echo
|
171
|
+
def escape_and_echo(file_contents)
|
172
|
+
file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|