chef-metal-ssh 0.0.3 → 0.0.4
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.
- data/README.md +7 -3
- data/lib/chef_metal_ssh/ssh_provisioner.rb +103 -21
- data/lib/chef_metal_ssh/version.rb +1 -1
- metadata +14 -39
data/README.md
CHANGED
|
@@ -26,8 +26,8 @@ Or install it yourself as:
|
|
|
26
26
|
provisioner ChefMetalSsh::SshProvisioner.new
|
|
27
27
|
provisioner_options 'target_ip' => '192.168.33.21',
|
|
28
28
|
'ssh_user' => 'vagrant',
|
|
29
|
-
'
|
|
30
|
-
'
|
|
29
|
+
'ssh_options' => {
|
|
30
|
+
'password' => 'vagrant'
|
|
31
31
|
}
|
|
32
32
|
recipe 'ssh_test::remote1'
|
|
33
33
|
notifies :create, 'machine[two]'
|
|
@@ -60,7 +60,11 @@ cd into the test directory:
|
|
|
60
60
|
|
|
61
61
|
then run:
|
|
62
62
|
|
|
63
|
-
`bash run_zero
|
|
63
|
+
`bash run_zero install_local` if you built the gem locally first using `rake build`
|
|
64
|
+
|
|
65
|
+
otherwise:
|
|
66
|
+
|
|
67
|
+
`bash run_zero install_rubygems`
|
|
64
68
|
|
|
65
69
|
this will install the prereqs. then run:
|
|
66
70
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'resolv'
|
|
1
2
|
require 'chef_metal/provisioner'
|
|
2
3
|
require 'chef_metal/version'
|
|
3
4
|
require 'chef_metal/machine/basic_machine'
|
|
@@ -27,17 +28,17 @@ module ChefMetalSsh
|
|
|
27
28
|
# node will have node['normal']['provisioner_options'] in it with any options.
|
|
28
29
|
# It is a hash with this format:
|
|
29
30
|
#
|
|
30
|
-
# -- provisioner_url: ssh
|
|
31
|
+
# -- provisioner_url: ssh:<@target_host>
|
|
31
32
|
# -- target_ip: the IP address of the target machine - IP or FQDN is required
|
|
32
33
|
# -- target_fqdn: The Resolvable name of the target machine - IP or FQDN is required
|
|
33
34
|
# -- ssh_user: the user to ssh as
|
|
34
|
-
# --
|
|
35
|
+
# -- ssh_options: options to pass the ssh command. available options are here - https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh.rb#L61
|
|
35
36
|
#
|
|
36
37
|
# node['normal']['provisioner_output'] will be populated with information
|
|
37
38
|
# about the created machine. For ssh, it is a hash with this
|
|
38
39
|
# format:
|
|
39
40
|
#
|
|
40
|
-
# -- provisioner_url: ssh
|
|
41
|
+
# -- provisioner_url: ssh:<@target_host>
|
|
41
42
|
# -- name: container name
|
|
42
43
|
#
|
|
43
44
|
def acquire_machine(action_handler, node)
|
|
@@ -59,7 +60,7 @@ module ChefMetalSsh
|
|
|
59
60
|
# Set up Provisioner Output
|
|
60
61
|
# TODO - make url the chef server url path? maybe disk path if zero?
|
|
61
62
|
provisioner_output = node['normal']['provisioner_output'] || {
|
|
62
|
-
'provisioner_url' => "ssh:#{target_host}",
|
|
63
|
+
'provisioner_url' => "ssh:#{@target_host}",
|
|
63
64
|
'name' => node['name']
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -127,8 +128,28 @@ module ChefMetalSsh
|
|
|
127
128
|
if @target_host
|
|
128
129
|
remote_host = @target_host
|
|
129
130
|
elsif target_ip
|
|
131
|
+
raise 'Invalid IP' unless ( target_ip =~ Resolv::IPv4::Regex ||
|
|
132
|
+
target_ip =~ Resolv::IPv6::Regex )
|
|
130
133
|
remote_host = target_ip
|
|
131
134
|
elsif target_fqdn
|
|
135
|
+
rh = Resolv::Hosts.new
|
|
136
|
+
rd = Resolv.new
|
|
137
|
+
|
|
138
|
+
begin
|
|
139
|
+
rh.getaddress(target_fqdn)
|
|
140
|
+
in_hosts_file = true
|
|
141
|
+
rescue
|
|
142
|
+
in_hosts_file = false
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
begin
|
|
146
|
+
rd.getaddress(target_fqdn)
|
|
147
|
+
in_dns = true
|
|
148
|
+
rescue
|
|
149
|
+
in_dns = false
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
raise 'Unresolvable Hostname' unless ( in_hosts_file || in_dns )
|
|
132
153
|
remote_host = target_fqdn
|
|
133
154
|
else
|
|
134
155
|
raise "aint got no target yo, that dog dont hunt"
|
|
@@ -151,12 +172,26 @@ module ChefMetalSsh
|
|
|
151
172
|
end
|
|
152
173
|
end
|
|
153
174
|
|
|
175
|
+
def symbolize_keys(hash)
|
|
176
|
+
hash.inject({}){|result, (key, value)|
|
|
177
|
+
new_key = case key
|
|
178
|
+
when String then key.to_sym
|
|
179
|
+
else key
|
|
180
|
+
end
|
|
181
|
+
new_value = case value
|
|
182
|
+
when Hash then symbolize_keys(value)
|
|
183
|
+
else value
|
|
184
|
+
end
|
|
185
|
+
result[new_key] = new_value
|
|
186
|
+
result
|
|
187
|
+
}
|
|
188
|
+
end
|
|
189
|
+
|
|
154
190
|
# Setup Ssh
|
|
155
191
|
def create_ssh_transport(node)
|
|
156
|
-
# TODO - verify target_host resolves
|
|
157
|
-
# Verify Valid IP
|
|
158
192
|
|
|
159
|
-
provisioner_options
|
|
193
|
+
provisioner_options = node['normal']['provisioner_options']
|
|
194
|
+
provisioner_ssh_options = provisioner_options['ssh_options']
|
|
160
195
|
|
|
161
196
|
Chef::Log.debug("======================================>")
|
|
162
197
|
Chef::Log.debug("create_ssh_transport - target_host: #{@target_host}")
|
|
@@ -164,8 +199,8 @@ module ChefMetalSsh
|
|
|
164
199
|
|
|
165
200
|
##
|
|
166
201
|
# Ssh Username
|
|
167
|
-
username
|
|
168
|
-
username
|
|
202
|
+
username = ''
|
|
203
|
+
username = provisioner_options['ssh_user'] || 'vagrant'
|
|
169
204
|
|
|
170
205
|
Chef::Log.debug("======================================>")
|
|
171
206
|
Chef::Log.debug("create_ssh_transport - username: #{username}")
|
|
@@ -173,29 +208,76 @@ module ChefMetalSsh
|
|
|
173
208
|
|
|
174
209
|
##
|
|
175
210
|
# Ssh Password
|
|
176
|
-
ssh_pass =
|
|
177
|
-
ssh_pass =
|
|
211
|
+
ssh_pass = false
|
|
212
|
+
ssh_pass = provisioner_ssh_options['password'] if provisioner_ssh_options['password']
|
|
213
|
+
# ssh_pass = ssh_options[:password] if ssh_options[:password]
|
|
214
|
+
|
|
215
|
+
##
|
|
216
|
+
# Ssh Key
|
|
217
|
+
ssh_key = false
|
|
218
|
+
ssh_key = provisioner_ssh_options['host_key'] if provisioner_ssh_options['host_key']
|
|
178
219
|
|
|
179
220
|
Chef::Log.debug("======================================>")
|
|
180
|
-
|
|
221
|
+
if ssh_pass
|
|
222
|
+
Chef::Log.debug("create_ssh_transport - ssh_pass: #{ssh_pass}")
|
|
223
|
+
elsif ssh_key
|
|
224
|
+
Chef::Log.debug("create_ssh_transport - ssh_key: #{ssh_key}")
|
|
225
|
+
else
|
|
226
|
+
Chef::Log.debug("create_ssh_transport - no ssh_pass or ssh_key given")
|
|
227
|
+
end
|
|
181
228
|
Chef::Log.debug("======================================>")
|
|
182
229
|
|
|
230
|
+
raise "no ssh_pass or ssh_key given" unless ( ssh_pass || ssh_key )
|
|
183
231
|
##
|
|
184
232
|
# Ssh Main Options
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
:
|
|
192
|
-
:
|
|
193
|
-
|
|
233
|
+
valid_ssh_options = [
|
|
234
|
+
:auth_methods, :bind_address, :compression, :compression_level, :config,
|
|
235
|
+
:encryption, :forward_agent, :hmac, :host_key,
|
|
236
|
+
:keepalive, :keepalive_interval, :kex, :keys, :key_data,
|
|
237
|
+
:languages, :logger, :paranoid, :password, :port, :proxy,
|
|
238
|
+
:rekey_blocks_limit,:rekey_limit, :rekey_packet_limit, :timeout, :verbose,
|
|
239
|
+
:global_known_hosts_file, :user_known_hosts_file, :host_key_alias,
|
|
240
|
+
:host_name, :user, :properties, :passphrase, :keys_only, :max_pkt_size,
|
|
241
|
+
:max_win_size, :send_env, :use_agent
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
##
|
|
245
|
+
# Ssh Main Options
|
|
246
|
+
ssh_options = symbolize_keys(provisioner_ssh_options)
|
|
247
|
+
|
|
248
|
+
# Validate Ssh Options
|
|
249
|
+
ssh_options.each { |k,v| raise 'Invalid Shh Option' unless valid_ssh_options.include?(k) }
|
|
250
|
+
|
|
251
|
+
##
|
|
252
|
+
# Ssh Main Options
|
|
253
|
+
# ssh_options = symbolize_keys(provisioner_ssh_options)
|
|
254
|
+
# ssh_options = {
|
|
255
|
+
# # TODO create a user known hosts file
|
|
256
|
+
# # :user_known_hosts_file => provisioner_options['ssh_connect_options']['UserKnownHostsFile'],
|
|
257
|
+
# # :paranoid => true,
|
|
258
|
+
# # :auth_methods => [ 'publickey' ],
|
|
259
|
+
# :keys_only => false,
|
|
260
|
+
# :host_key => ssh_key,
|
|
261
|
+
# :password => ssh_pass
|
|
262
|
+
# }
|
|
194
263
|
|
|
195
264
|
Chef::Log.debug("======================================>")
|
|
196
265
|
Chef::Log.debug("create_ssh_transport - ssh_options: #{ssh_options.inspect}")
|
|
197
266
|
Chef::Log.debug("======================================>")
|
|
198
267
|
|
|
268
|
+
# Make Sure We Can Connect
|
|
269
|
+
begin
|
|
270
|
+
ssh = Net::SSH.start(@target_host, username, ssh_options)
|
|
271
|
+
ssh.close
|
|
272
|
+
Chef::Log.debug("======================================>")
|
|
273
|
+
Chef::Log.debug("ABLE to Connect to #{@target_host} using #{username} and #{ssh_options.inspect}")
|
|
274
|
+
Chef::Log.debug("======================================>")
|
|
275
|
+
rescue
|
|
276
|
+
Chef::Log.debug("======================================>")
|
|
277
|
+
Chef::Log.debug("UNABLE to Connect to #{@target_host} using #{username} and #{ssh_options.inspect}")
|
|
278
|
+
Chef::Log.debug("======================================>")
|
|
279
|
+
raise "UNABLE to Connect to #{@target_host} using #{username} and #{ssh_options.inspect}"
|
|
280
|
+
end
|
|
199
281
|
|
|
200
282
|
##
|
|
201
283
|
# Ssh Additional Options
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chef-metal-ssh
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-04-
|
|
12
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: chef
|
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirement: &13107560 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,15 +21,10 @@ dependencies:
|
|
|
21
21
|
version: '0'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
25
|
-
none: false
|
|
26
|
-
requirements:
|
|
27
|
-
- - ! '>='
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: '0'
|
|
24
|
+
version_requirements: *13107560
|
|
30
25
|
- !ruby/object:Gem::Dependency
|
|
31
26
|
name: chef-metal
|
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
|
27
|
+
requirement: &13163400 !ruby/object:Gem::Requirement
|
|
33
28
|
none: false
|
|
34
29
|
requirements:
|
|
35
30
|
- - ~>
|
|
@@ -37,15 +32,10 @@ dependencies:
|
|
|
37
32
|
version: '0.6'
|
|
38
33
|
type: :runtime
|
|
39
34
|
prerelease: false
|
|
40
|
-
version_requirements:
|
|
41
|
-
none: false
|
|
42
|
-
requirements:
|
|
43
|
-
- - ~>
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
version: '0.6'
|
|
35
|
+
version_requirements: *13163400
|
|
46
36
|
- !ruby/object:Gem::Dependency
|
|
47
37
|
name: bundler
|
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
|
38
|
+
requirement: &13161940 !ruby/object:Gem::Requirement
|
|
49
39
|
none: false
|
|
50
40
|
requirements:
|
|
51
41
|
- - ~>
|
|
@@ -53,15 +43,10 @@ dependencies:
|
|
|
53
43
|
version: '1.5'
|
|
54
44
|
type: :development
|
|
55
45
|
prerelease: false
|
|
56
|
-
version_requirements:
|
|
57
|
-
none: false
|
|
58
|
-
requirements:
|
|
59
|
-
- - ~>
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '1.5'
|
|
46
|
+
version_requirements: *13161940
|
|
62
47
|
- !ruby/object:Gem::Dependency
|
|
63
48
|
name: rspec
|
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirement: &13160480 !ruby/object:Gem::Requirement
|
|
65
50
|
none: false
|
|
66
51
|
requirements:
|
|
67
52
|
- - ! '>='
|
|
@@ -69,15 +54,10 @@ dependencies:
|
|
|
69
54
|
version: '0'
|
|
70
55
|
type: :development
|
|
71
56
|
prerelease: false
|
|
72
|
-
version_requirements:
|
|
73
|
-
none: false
|
|
74
|
-
requirements:
|
|
75
|
-
- - ! '>='
|
|
76
|
-
- !ruby/object:Gem::Version
|
|
77
|
-
version: '0'
|
|
57
|
+
version_requirements: *13160480
|
|
78
58
|
- !ruby/object:Gem::Dependency
|
|
79
59
|
name: rake
|
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
|
60
|
+
requirement: &13158020 !ruby/object:Gem::Requirement
|
|
81
61
|
none: false
|
|
82
62
|
requirements:
|
|
83
63
|
- - ! '>='
|
|
@@ -85,12 +65,7 @@ dependencies:
|
|
|
85
65
|
version: '0'
|
|
86
66
|
type: :development
|
|
87
67
|
prerelease: false
|
|
88
|
-
version_requirements:
|
|
89
|
-
none: false
|
|
90
|
-
requirements:
|
|
91
|
-
- - ! '>='
|
|
92
|
-
- !ruby/object:Gem::Version
|
|
93
|
-
version: '0'
|
|
68
|
+
version_requirements: *13158020
|
|
94
69
|
description: Provisioner for managing servers using ssh in Chef Metal.
|
|
95
70
|
email: zackzondlo@gmail.com
|
|
96
71
|
executables: []
|
|
@@ -102,8 +77,8 @@ files:
|
|
|
102
77
|
- Rakefile
|
|
103
78
|
- LICENSE.txt
|
|
104
79
|
- README.md
|
|
105
|
-
- lib/chef_metal_ssh.rb
|
|
106
80
|
- lib/chef_metal/provisioner_init/ssh_init.rb
|
|
81
|
+
- lib/chef_metal_ssh.rb
|
|
107
82
|
- lib/chef_metal_ssh/ssh_provisioner.rb
|
|
108
83
|
- lib/chef_metal_ssh/version.rb
|
|
109
84
|
homepage: https://github.com/double-z/chef-metal-ssh
|
|
@@ -126,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
126
101
|
version: '0'
|
|
127
102
|
requirements: []
|
|
128
103
|
rubyforge_project:
|
|
129
|
-
rubygems_version: 1.8.
|
|
104
|
+
rubygems_version: 1.8.11
|
|
130
105
|
signing_key:
|
|
131
106
|
specification_version: 3
|
|
132
107
|
summary: Provisioner for managing servers using ssh in Chef Metal.
|