knife-windows 0.8.6.rc.0 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,222 +1,222 @@
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'
20
- require 'chef/knife/bootstrap'
21
- require 'chef/encrypted_data_bag_item'
22
- require 'chef/knife/core/windows_bootstrap_context'
23
-
24
- class Chef
25
- class Knife
26
- module BootstrapWindowsBase
27
-
28
- # :nodoc:
29
- # Would prefer to do this in a rational way, but can't be done b/c of
30
- # Mixlib::CLI's design :(
31
- def self.included(includer)
32
- includer.class_eval do
33
-
34
- deps do
35
- require 'readline'
36
- require 'chef/json_compat'
37
- end
38
-
39
- option :chef_node_name,
40
- :short => "-N NAME",
41
- :long => "--node-name NAME",
42
- :description => "The Chef node name for your new node"
43
-
44
- option :prerelease,
45
- :long => "--prerelease",
46
- :description => "Install the pre-release chef gems"
47
-
48
- option :bootstrap_version,
49
- :long => "--bootstrap-version VERSION",
50
- :description => "The version of Chef to install",
51
- :proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
52
-
53
- option :bootstrap_proxy,
54
- :long => "--bootstrap-proxy PROXY_URL",
55
- :description => "The proxy server for the node being bootstrapped",
56
- :proc => Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p }
57
-
58
- option :bootstrap_no_proxy,
59
- :long => "--bootstrap-no-proxy ",
60
- :description => "Avoid a proxy server for the given addresses",
61
- :proc => Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np }
62
-
63
- option :distro,
64
- :short => "-d DISTRO",
65
- :long => "--distro DISTRO",
66
- :description => "Bootstrap a distro using a template",
67
- :default => "windows-chef-client-msi"
68
-
69
- option :template_file,
70
- :long => "--template-file TEMPLATE",
71
- :description => "Full path to location of template to use",
72
- :default => false
73
-
74
- option :run_list,
75
- :short => "-r RUN_LIST",
76
- :long => "--run-list RUN_LIST",
77
- :description => "Comma separated list of roles/recipes to apply",
78
- :proc => lambda { |o| o.split(",") },
79
- :default => []
80
-
81
- option :first_boot_attributes,
82
- :short => "-j JSON_ATTRIBS",
83
- :long => "--json-attributes",
84
- :description => "A JSON string to be added to the first run of chef-client",
85
- :proc => lambda { |o| JSON.parse(o) },
86
- :default => {}
87
-
88
- option :encrypted_data_bag_secret,
89
- :short => "-s SECRET",
90
- :long => "--secret ",
91
- :description => "The secret key to use to decrypt data bag item values. Will be rendered on the node at c:/chef/encrypted_data_bag_secret and set in the rendered client config.",
92
- :default => false
93
-
94
- option :encrypted_data_bag_secret_file,
95
- :long => "--secret-file SECRET_FILE",
96
- :description => "A file containing the secret key to use to encrypt data bag item values. Will be rendered on the node at c:/chef/encrypted_data_bag_secret and set in the rendered client config."
97
-
98
- option :auth_timeout,
99
- :long => "--auth-timeout MINUTES",
100
- :description => "The maximum time in minutes to wait to for authentication over the transport to the node to succeed. The default value is 2 minutes.",
101
- :default => 2
102
-
103
- option :node_ssl_verify_mode,
104
- :long => "--node-ssl-verify-mode [peer|none]",
105
- :description => "Whether or not to verify the SSL cert for all HTTPS requests.",
106
- :proc => Proc.new { |v|
107
- valid_values = ["none", "peer"]
108
- unless valid_values.include?(v)
109
- raise "Invalid value '#{v}' for --node-ssl-verify-mode. Valid values are: #{valid_values.join(", ")}"
110
- end
111
- }
112
-
113
- option :node_verify_api_cert,
114
- :long => "--[no-]node-verify-api-cert",
115
- :description => "Verify the SSL cert for HTTPS requests to the Chef server API.",
116
- :boolean => true
117
- end
118
- end
119
-
120
- # TODO: This should go away when CHEF-2193 is fixed
121
- def load_template(template=nil)
122
- # Are we bootstrapping using an already shipped template?
123
- if config[:template_file]
124
- bootstrap_files = config[:template_file]
125
- else
126
- bootstrap_files = []
127
- bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap', "#{config[:distro]}.erb")
128
- bootstrap_files << File.join(Dir.pwd, ".chef", "bootstrap", "#{config[:distro]}.erb")
129
- bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{config[:distro]}.erb")
130
- bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{config[:distro]}.erb"))
131
- bootstrap_files.flatten!
132
- end
133
-
134
- template = Array(bootstrap_files).find do |bootstrap_template|
135
- Chef::Log.debug("Looking for bootstrap template in #{File.dirname(bootstrap_template)}")
136
- ::File.exists?(bootstrap_template)
137
- end
138
-
139
- unless template
140
- ui.info("Can not find bootstrap definition for #{config[:distro]}")
141
- raise Errno::ENOENT
142
- end
143
-
144
- Chef::Log.debug("Found bootstrap template in #{File.dirname(template)}")
145
-
146
- IO.read(template).chomp
147
- end
148
-
149
- def render_template(template=nil)
150
- if config[:encrypted_data_bag_secret_file]
151
- config[:encrypted_data_bag_secret] = Chef::EncryptedDataBagItem.load_secret(config[:encrypted_data_bag_secret_file])
152
- end
153
- context = Knife::Core::WindowsBootstrapContext.new(config, config[:run_list], Chef::Config)
154
- Erubis::Eruby.new(template).evaluate(context)
155
- end
156
-
157
- def bootstrap(proto=nil)
158
- validate_name_args!
159
-
160
- @node_name = Array(@name_args).first
161
- # back compat--templates may use this setting:
162
- config[:server_name] = @node_name
163
-
164
- STDOUT.sync = STDERR.sync = true
165
-
166
- wait_for_remote_response( config[:auth_timeout].to_i )
167
- ui.info("Bootstrapping Chef on #{ui.color(@node_name, :bold)}")
168
- # create a bootstrap.bat file on the node
169
- # we have to run the remote commands in 2047 char chunks
170
- create_bootstrap_bat_command do |command_chunk, chunk_num|
171
- begin
172
- render_command_result = run_command(%Q!cmd.exe /C echo "Rendering #{bootstrap_bat_file} chunk #{chunk_num}" && #{command_chunk}!)
173
- ui.error("Batch render command returned #{render_command_result}") if render_command_result != 0
174
- render_command_result
175
- rescue SystemExit => e
176
- raise unless e.success?
177
- end
178
- end
179
-
180
- # execute the bootstrap.bat file
181
- bootstrap_command_result = run_command(bootstrap_command)
182
- ui.error("Bootstrap command returned #{bootstrap_command_result}") if bootstrap_command_result != 0
183
- bootstrap_command_result
184
- end
185
-
186
- protected
187
-
188
- # Default implementation -- override only if required by the transport
189
- def wait_for_remote_response(wait_max_minutes)
190
- end
191
-
192
- def bootstrap_command
193
- @bootstrap_command ||= "cmd.exe /C #{bootstrap_bat_file}"
194
- end
195
-
196
- def create_bootstrap_bat_command(&block)
197
- bootstrap_bat = []
198
- chunk_num = 0
199
- render_template(load_template(config[:bootstrap_template])).each_line do |line|
200
- # escape WIN BATCH special chars
201
- line.gsub!(/[(<|>)^]/).each{|m| "^#{m}"}
202
- # windows commands are limited to 2047 characters
203
- if((bootstrap_bat + [line]).join(" && ").size > 2047 )
204
- yield bootstrap_bat.join(" && "), chunk_num += 1
205
- bootstrap_bat = []
206
- end
207
- bootstrap_bat << ">> #{bootstrap_bat_file} (echo.#{line.chomp.strip})"
208
- end
209
- yield bootstrap_bat.join(" && "), chunk_num += 1
210
- end
211
-
212
- def bootstrap_bat_file
213
- @bootstrap_bat_file ||= "\"%TEMP%\\bootstrap-#{Process.pid}-#{Time.now.to_i}.bat\""
214
- end
215
-
216
- def locate_config_value(key)
217
- key = key.to_sym
218
- Chef::Config[:knife][key] || config[key]
219
- end
220
- end
221
- end
222
- 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'
20
+ require 'chef/knife/bootstrap'
21
+ require 'chef/encrypted_data_bag_item'
22
+ require 'chef/knife/core/windows_bootstrap_context'
23
+
24
+ class Chef
25
+ class Knife
26
+ module BootstrapWindowsBase
27
+
28
+ # :nodoc:
29
+ # Would prefer to do this in a rational way, but can't be done b/c of
30
+ # Mixlib::CLI's design :(
31
+ def self.included(includer)
32
+ includer.class_eval do
33
+
34
+ deps do
35
+ require 'readline'
36
+ require 'chef/json_compat'
37
+ end
38
+
39
+ option :chef_node_name,
40
+ :short => "-N NAME",
41
+ :long => "--node-name NAME",
42
+ :description => "The Chef node name for your new node"
43
+
44
+ option :prerelease,
45
+ :long => "--prerelease",
46
+ :description => "Install the pre-release chef gems"
47
+
48
+ option :bootstrap_version,
49
+ :long => "--bootstrap-version VERSION",
50
+ :description => "The version of Chef to install",
51
+ :proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
52
+
53
+ option :bootstrap_proxy,
54
+ :long => "--bootstrap-proxy PROXY_URL",
55
+ :description => "The proxy server for the node being bootstrapped",
56
+ :proc => Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p }
57
+
58
+ option :bootstrap_no_proxy,
59
+ :long => "--bootstrap-no-proxy ",
60
+ :description => "Avoid a proxy server for the given addresses",
61
+ :proc => Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np }
62
+
63
+ option :distro,
64
+ :short => "-d DISTRO",
65
+ :long => "--distro DISTRO",
66
+ :description => "Bootstrap a distro using a template",
67
+ :default => "windows-chef-client-msi"
68
+
69
+ option :template_file,
70
+ :long => "--template-file TEMPLATE",
71
+ :description => "Full path to location of template to use",
72
+ :default => false
73
+
74
+ option :run_list,
75
+ :short => "-r RUN_LIST",
76
+ :long => "--run-list RUN_LIST",
77
+ :description => "Comma separated list of roles/recipes to apply",
78
+ :proc => lambda { |o| o.split(",") },
79
+ :default => []
80
+
81
+ option :first_boot_attributes,
82
+ :short => "-j JSON_ATTRIBS",
83
+ :long => "--json-attributes",
84
+ :description => "A JSON string to be added to the first run of chef-client",
85
+ :proc => lambda { |o| JSON.parse(o) },
86
+ :default => {}
87
+
88
+ option :encrypted_data_bag_secret,
89
+ :short => "-s SECRET",
90
+ :long => "--secret ",
91
+ :description => "The secret key to use to decrypt data bag item values. Will be rendered on the node at c:/chef/encrypted_data_bag_secret and set in the rendered client config.",
92
+ :default => false
93
+
94
+ option :encrypted_data_bag_secret_file,
95
+ :long => "--secret-file SECRET_FILE",
96
+ :description => "A file containing the secret key to use to encrypt data bag item values. Will be rendered on the node at c:/chef/encrypted_data_bag_secret and set in the rendered client config."
97
+
98
+ option :auth_timeout,
99
+ :long => "--auth-timeout MINUTES",
100
+ :description => "The maximum time in minutes to wait to for authentication over the transport to the node to succeed. The default value is 2 minutes.",
101
+ :default => 2
102
+
103
+ option :node_ssl_verify_mode,
104
+ :long => "--node-ssl-verify-mode [peer|none]",
105
+ :description => "Whether or not to verify the SSL cert for all HTTPS requests.",
106
+ :proc => Proc.new { |v|
107
+ valid_values = ["none", "peer"]
108
+ unless valid_values.include?(v)
109
+ raise "Invalid value '#{v}' for --node-ssl-verify-mode. Valid values are: #{valid_values.join(", ")}"
110
+ end
111
+ }
112
+
113
+ option :node_verify_api_cert,
114
+ :long => "--[no-]node-verify-api-cert",
115
+ :description => "Verify the SSL cert for HTTPS requests to the Chef server API.",
116
+ :boolean => true
117
+ end
118
+ end
119
+
120
+ # TODO: This should go away when CHEF-2193 is fixed
121
+ def load_template(template=nil)
122
+ # Are we bootstrapping using an already shipped template?
123
+ if config[:template_file]
124
+ bootstrap_files = config[:template_file]
125
+ else
126
+ bootstrap_files = []
127
+ bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap', "#{config[:distro]}.erb")
128
+ bootstrap_files << File.join(Dir.pwd, ".chef", "bootstrap", "#{config[:distro]}.erb")
129
+ bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{config[:distro]}.erb")
130
+ bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{config[:distro]}.erb"))
131
+ bootstrap_files.flatten!
132
+ end
133
+
134
+ template = Array(bootstrap_files).find do |bootstrap_template|
135
+ Chef::Log.debug("Looking for bootstrap template in #{File.dirname(bootstrap_template)}")
136
+ ::File.exists?(bootstrap_template)
137
+ end
138
+
139
+ unless template
140
+ ui.info("Can not find bootstrap definition for #{config[:distro]}")
141
+ raise Errno::ENOENT
142
+ end
143
+
144
+ Chef::Log.debug("Found bootstrap template in #{File.dirname(template)}")
145
+
146
+ IO.read(template).chomp
147
+ end
148
+
149
+ def render_template(template=nil)
150
+ if config[:encrypted_data_bag_secret_file]
151
+ config[:encrypted_data_bag_secret] = Chef::EncryptedDataBagItem.load_secret(config[:encrypted_data_bag_secret_file])
152
+ end
153
+ context = Knife::Core::WindowsBootstrapContext.new(config, config[:run_list], Chef::Config)
154
+ Erubis::Eruby.new(template).evaluate(context)
155
+ end
156
+
157
+ def bootstrap(proto=nil)
158
+ validate_name_args!
159
+
160
+ @node_name = Array(@name_args).first
161
+ # back compat--templates may use this setting:
162
+ config[:server_name] = @node_name
163
+
164
+ STDOUT.sync = STDERR.sync = true
165
+
166
+ wait_for_remote_response( config[:auth_timeout].to_i )
167
+ ui.info("Bootstrapping Chef on #{ui.color(@node_name, :bold)}")
168
+ # create a bootstrap.bat file on the node
169
+ # we have to run the remote commands in 2047 char chunks
170
+ create_bootstrap_bat_command do |command_chunk, chunk_num|
171
+ begin
172
+ render_command_result = run_command(%Q!cmd.exe /C echo "Rendering #{bootstrap_bat_file} chunk #{chunk_num}" && #{command_chunk}!)
173
+ ui.error("Batch render command returned #{render_command_result}") if render_command_result != 0
174
+ render_command_result
175
+ rescue SystemExit => e
176
+ raise unless e.success?
177
+ end
178
+ end
179
+
180
+ # execute the bootstrap.bat file
181
+ bootstrap_command_result = run_command(bootstrap_command)
182
+ ui.error("Bootstrap command returned #{bootstrap_command_result}") if bootstrap_command_result != 0
183
+ bootstrap_command_result
184
+ end
185
+
186
+ protected
187
+
188
+ # Default implementation -- override only if required by the transport
189
+ def wait_for_remote_response(wait_max_minutes)
190
+ end
191
+
192
+ def bootstrap_command
193
+ @bootstrap_command ||= "cmd.exe /C #{bootstrap_bat_file}"
194
+ end
195
+
196
+ def create_bootstrap_bat_command(&block)
197
+ bootstrap_bat = []
198
+ chunk_num = 0
199
+ render_template(load_template(config[:bootstrap_template])).each_line do |line|
200
+ # escape WIN BATCH special chars
201
+ line.gsub!(/[(<|>)^]/).each{|m| "^#{m}"}
202
+ # windows commands are limited to 2047 characters
203
+ if((bootstrap_bat + [line]).join(" && ").size > 2047 )
204
+ yield bootstrap_bat.join(" && "), chunk_num += 1
205
+ bootstrap_bat = []
206
+ end
207
+ bootstrap_bat << ">> #{bootstrap_bat_file} (echo.#{line.chomp.strip})"
208
+ end
209
+ yield bootstrap_bat.join(" && "), chunk_num += 1
210
+ end
211
+
212
+ def bootstrap_bat_file
213
+ @bootstrap_bat_file ||= "\"%TEMP%\\bootstrap-#{Process.pid}-#{Time.now.to_i}.bat\""
214
+ end
215
+
216
+ def locate_config_value(key)
217
+ key = key.to_sym
218
+ Chef::Config[:knife][key] || config[key]
219
+ end
220
+ end
221
+ end
222
+ end
@@ -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