chef-provisioning-ssh 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6aae7c38cadd63e7e9f24c09b92e70a2ce89f4db
4
- data.tar.gz: b5e34e1c06a4eb66dfbf553ebf374aa08673d0ce
3
+ metadata.gz: 7fe4cf3899fb309821ab22d0f9dd76fadcc1b58c
4
+ data.tar.gz: 0f80251b6a818fbe5c7ed42445b635cc9333aed5
5
5
  SHA512:
6
- metadata.gz: de89311eb5a7e788650dc0ec9e277472c582c721a8799bbe4b7e14345e5470c89db760de0184e4823c68d2a1f6915291a28bb542bbb844a9e6bf1ad224d34d71
7
- data.tar.gz: 745f02e2a483c1ffe38523782fc46219684ca32c2d3dd041af26d59a64802fe025cc371d3f57e49c69614b6ac365e7b67ad0aa4e8d34905914a373c2f188a092
6
+ metadata.gz: df8767e9f50ddd4d670efeb8ffe1a06c1acff06a7c7260e9c97b3e7a7505c37fbfa0c1fa793e3f40cef76e06bf69304edb95ae17a4b5c894a9a9a579c9abadcb
7
+ data.tar.gz: 3a353beff910734a9ab9be8bd8181af14f34999ecd0d8b98c55426e521a18f338aa612168ac3eb7904ae982a1ab490851630bfae213204ecabebdd3c04e4ae9d
data/README.md CHANGED
@@ -41,48 +41,73 @@ The snippet from that link is:
41
41
  chef, or the username configured in .ssh/config).
42
42
 
43
43
  The options are used in
44
- Net::SSH.start(host, username, ssh_options)
44
+ Net::SSH.start(host, username, ssh_options, options)
45
45
 
46
46
  In addition to host, ip_address and hostname are also additional options.
47
47
 
48
- * valid ssh options are:
49
-
50
- :auth_methods,
51
- :bind_address,
52
- :compression,
53
- :compression_level,
54
- :config,
55
- :encryption,
56
- :forward_agent,
57
- :hmac,
58
- :host_key,
59
- :keepalive,
60
- :keepalive_interval,
61
- :kex,
62
- :keys,
63
- :key_data,
64
- :languages,
65
- :logger,
66
- :paranoid,
67
- :password,
68
- :port,
69
- :proxy,
70
- :rekey_blocks_limit,
71
- :rekey_limit,
72
- :rekey_packet_limit,
73
- :timeout,
74
- :verbose,
75
- :global_known_hosts_file,
76
- :user_known_hosts_file,
77
- :host_key_alias,
78
- :host_name,
79
- :user,
80
- :properties,
81
- :passphrase,
82
- :keys_only,
83
- :max_pkt_size,
84
- :max_win_size, :send_env,
85
- :use_agent
48
+
49
+ * full machine_options for SSH example:
50
+
51
+ with_machine_options :transport_options => {
52
+ 'is_windows' => false,
53
+ 'ip_address' => '192.168.33.23',
54
+ 'host' => 'somehost',
55
+ 'username' => 'vagrant',
56
+ 'ssh_options' => {
57
+ 'auth_methods' => '',
58
+ 'bind_address' => '',
59
+ 'compression' => '',
60
+ 'compression_level' => '',
61
+ 'config' => '',
62
+ 'encryption' => '',
63
+ 'forward_agent' => '',
64
+ 'hmac' => '',
65
+ 'host_key' => '',
66
+ 'keepalive' => '',
67
+ 'keepalive_interval' => '',
68
+ 'kex' => '',
69
+ 'keys' => ['/home/username/.vagrant.d/insecure_private_key'],
70
+ 'key_data' => '',
71
+ 'languages' => '',
72
+ 'logger' => '',
73
+ 'paranoid' => '',
74
+ 'password' => '',
75
+ 'port' => '',
76
+ 'proxy' => '',
77
+ 'rekey_blocks_limit' => '',
78
+ 'rekey_limit' => '',
79
+ 'rekey_packet_limit' => '',
80
+ 'timeout' => '',
81
+ 'verbose' => '',
82
+ 'global_known_hosts_file' => '',
83
+ 'user_known_hosts_file' => '',
84
+ 'host_key_alias' => '',
85
+ 'host_name' => '',
86
+ 'user' => '',
87
+ 'properties' => '',
88
+ 'passphrase' => '',
89
+ 'keys_only' => '',
90
+ 'max_pkt_size' => '',
91
+ 'max_win_size, :send_env' => '',
92
+ 'use_agent' => ''
93
+ },
94
+ 'options' => {
95
+ 'prefix' => 'sudo ',
96
+ 'ssh_pty_enable' => false,
97
+ 'ssh_gateway' => 'yourgateway'
98
+ }
99
+ }
100
+
101
+ * full machine_options for WinRM example:
102
+
103
+ with_machine_options :transport_options => {
104
+ 'is_windows' => true,
105
+ 'host' => '192.168.33.23',
106
+ 'port' => 5985,
107
+ 'username' => 'vagrant',
108
+ 'password' => 'vagrant'
109
+ }
110
+
86
111
 
87
112
  * machine resource example:
88
113
 
@@ -90,9 +115,9 @@ In addition to host, ip_address and hostname are also additional options.
90
115
 
91
116
  with_driver 'ssh'
92
117
 
93
- machine "sshone" do
118
+ machine "ssh" do
94
119
  action [:ready, :setup, :converge]
95
- machine_options 'transport_options' => {
120
+ machine_options :transport_options => {
96
121
  'ip_address' => '192.168.33.22',
97
122
  'username' => 'vagrant',
98
123
  'ssh_options' => {
@@ -103,16 +128,23 @@ In addition to host, ip_address and hostname are also additional options.
103
128
  converge true
104
129
  end
105
130
 
106
- machine "sshtwo" do
131
+ ##
132
+ # With WinRM you must use a remote chef-server
133
+ # local-mode chef server is not currently supported
134
+
135
+ with_chef_server "https://api.opscode.com/organizations/double-z",
136
+ :client_name => Chef::Config[:node_name],
137
+ :signing_key_filename => Chef::Config[:client_key]
138
+
139
+ machine "winrm" do
107
140
  action [:ready, :setup, :converge]
108
141
  machine_options :transport_options => {
109
- 'ip_address' => '192.168.33.23',
142
+ 'host' => '192.168.33.23',
143
+ 'port' => 5985,
110
144
  'username' => 'vagrant',
111
- 'ssh_options' => {
112
- 'keys' => ['/home/username/.vagrant.d/insecure_private_key']
113
- }
145
+ 'password' => 'vagrant'
114
146
  }
115
- recipe 'vagrant::sshtwo'
147
+ recipe 'windows'
116
148
  converge true
117
149
  end
118
150
 
@@ -133,6 +165,8 @@ Then run from the test directory:
133
165
 
134
166
  `chef-client -z -o vagrant::test_provisioning_ssh`
135
167
 
168
+ NOTE: if the second machine fails it will be a result of issues with your vagrant key.
169
+
136
170
  This will run chef-provisioning on each of the two vagrant nodes.
137
171
 
138
172
  thats it.
@@ -4,7 +4,10 @@ require 'chef/provisioning/driver'
4
4
  require 'chef/provisioning/version'
5
5
  require 'chef/provisioning/machine/basic_machine'
6
6
  require 'chef/provisioning/machine/unix_machine'
7
+ require 'chef/provisioning/machine/windows_machine'
8
+ require 'chef/provisioning/convergence_strategy/install_msi'
7
9
  require 'chef/provisioning/convergence_strategy/install_cached'
10
+ require 'chef/provisioning/transport/winrm'
8
11
  require 'chef/provisioning/transport/ssh'
9
12
  require 'chef/provisioning/ssh_driver/version'
10
13
  require 'chef/provisioning/ssh_driver/helpers'
@@ -54,87 +57,97 @@ class Chef
54
57
  new_machine = false
55
58
  new_machine_options = {}
56
59
  current_machine_options = false
57
-
58
- if machine_options[:transport_options]
59
- new_machine_options['transport_options'] = machine_options[:transport_options]
60
- elsif machine_options['transport_options']
61
- new_machine_options['transport_options'] = machine_options['transport_options']
62
- end
63
60
 
64
- if machine_options[:convergence_options]
65
- new_machine_options['convergence_options'] = machine_options[:convergence_options]
66
- elsif machine_options['convergence_options']
67
- new_machine_options['convergence_options'] = machine_options['convergence_options']
68
- end
61
+ if machine_options[:transport_options] && machine_options[:transport_options]['is_windows']
69
62
 
70
- if machine_spec.location && ssh_machine_exists?(machine_spec.name)
71
- _current_machine_options = existing_machine_hash(machine_spec)
72
- current_machine_options = stringify_keys(_current_machine_options.dup)
73
- end
63
+ machine_spec.location = {
64
+ 'driver_url' => driver_url,
65
+ 'driver_version' => Chef::Provisioning::SshDriver::VERSION,
66
+ 'target_name' => machine_spec.name,
67
+ 'ssh_file_path' => "#{cluster_path}/#{machine_spec.name}.json",
68
+ 'allocated_at' => Time.now.utc.to_s
69
+ }
74
70
 
75
- log_info "machine_spec.name #{machine_spec.name}"
71
+ else
76
72
 
77
- log_info "new_machine_options #{new_machine_options} \n\n current_machine_options #{current_machine_options}"
73
+ if machine_options[:transport_options]
74
+ new_machine_options['transport_options'] = machine_options[:transport_options]
75
+ elsif machine_options['transport_options']
76
+ new_machine_options['transport_options'] = machine_options['transport_options']
77
+ end
78
78
 
79
+ if machine_options[:convergence_options]
80
+ new_machine_options['convergence_options'] = machine_options[:convergence_options]
81
+ elsif machine_options['convergence_options']
82
+ new_machine_options['convergence_options'] = machine_options['convergence_options']
83
+ end
79
84
 
80
- machine_file_hash = updated_ssh_machine_file_hash(stringify_keys(new_machine_options),
81
- stringify_keys(current_machine_options))
85
+ if machine_spec.location && ssh_machine_exists?(machine_spec.name)
86
+ _current_machine_options = existing_machine_hash(machine_spec)
87
+ current_machine_options = stringify_keys(_current_machine_options.dup)
88
+ end
82
89
 
83
- raise 'machine File Hash Is Empty' unless machine_file_hash
84
- log_info("machine HASH = #{machine_file_hash}")
90
+ log_info "machine_spec.name #{machine_spec.name}"
85
91
 
86
- if machine_file_hash && machine_file_hash['transport_options']
87
- host_for(machine_file_hash['transport_options'])
88
- initialize_ssh(machine_file_hash['transport_options'])
89
- end
92
+ log_info "new_machine_options #{new_machine_options} \n\n current_machine_options #{current_machine_options}"
90
93
 
91
- machine_updated = create_ssh_machine_file(action_handler,
92
- machine_spec.name,
93
- machine_file_hash)
94
- machine_options_for(machine_file_hash)
95
94
 
96
- log_info("STRIPPED machine HASH = #{machine_file_hash}")
97
- log_info("UNSTRIPPED machine HASH = #{machine_file_hash}")
98
- log_info "machine_options_for #{machine_options_for}"
95
+ machine_file_hash = updated_ssh_machine_file_hash(stringify_keys(new_machine_options),
96
+ stringify_keys(current_machine_options))
99
97
 
100
- if machine_updated || !machine_spec.location
101
- machine_spec.location = {
102
- 'driver_url' => driver_url,
103
- 'driver_version' => Chef::Provisioning::SshDriver::VERSION,
104
- 'target_name' => machine_spec.name,
105
- 'ssh_file_path' => "#{cluster_path}/#{machine_spec.name}.json",
106
- 'allocated_at' => Time.now.utc.to_s
107
- }
108
- log_info("machine_spec.location= #{machine_spec.location}")
109
- end
110
- end
98
+ raise 'machine File Hash Is Empty' unless machine_file_hash
99
+ log_info("machine HASH = #{machine_file_hash}")
111
100
 
112
- def strip_hash_nil(val)
113
- vvv = case val
114
- when Hash
115
- cleaned_val = val.delete_if { |kk,vv| vv.nil? || (vv.is_a?(String) && vv.empty?) }
116
- cleaned_val.each do |k,v|
117
- case v
118
- when Hash
119
- strip_hash_nil(v)
120
- when Array
121
- v.flatten!
122
- v.uniq!
123
- end
101
+ if machine_file_hash && machine_file_hash['transport_options']
102
+ host_for(machine_file_hash['transport_options'])
103
+ initialize_ssh(machine_file_hash['transport_options'])
104
+ end
105
+
106
+ machine_updated = create_ssh_machine_file(action_handler,
107
+ machine_spec.name,
108
+ machine_file_hash)
109
+ machine_options_for(machine_file_hash)
110
+
111
+ log_info("STRIPPED machine HASH = #{machine_file_hash}")
112
+ log_info("UNSTRIPPED machine HASH = #{machine_file_hash}")
113
+ log_info "machine_options_for #{machine_options_for}"
114
+
115
+ if machine_updated || !machine_spec.location
116
+ machine_spec.location = {
117
+ 'driver_url' => driver_url,
118
+ 'driver_version' => Chef::Provisioning::SshDriver::VERSION,
119
+ 'target_name' => machine_spec.name,
120
+ 'ssh_file_path' => "#{cluster_path}/#{machine_spec.name}.json",
121
+ 'allocated_at' => Time.now.utc.to_s
122
+ }
123
+
124
+ # if machine_options[:transport_options]
125
+ # %w(winrm.host winrm.port winrm.username winrm.password).each do |key|
126
+ # machine_spec.location[key] = machine_options[:transport_options][key] if machine_options[:vagrant_options][key]
127
+ # end
128
+ # end
129
+
130
+ log_info("machine_spec.location= #{machine_spec.location}")
124
131
  end
125
132
  end
126
- # puts "VVV is #{vvv}"
127
- vvv
128
133
  end
129
134
 
130
135
  def ready_machine(action_handler, machine_spec, machine_options)
131
136
  allocate_machine(action_handler, machine_spec, machine_options)
132
- machine_for(machine_spec, machine_options_for)
137
+ if machine_options[:transport_options] && machine_options[:transport_options]['is_windows']
138
+ machine_for(machine_spec, machine_options)
139
+ else
140
+ machine_for(machine_spec, machine_options_for)
141
+ end
133
142
  end
134
143
 
135
144
  def connect_to_machine(machine_spec, machine_options)
136
145
  allocate_machine(action_handler, machine_spec, machine_options)
137
- machine_for(machine_spec, machine_options_for)
146
+ if machine_options[:transport_options] && machine_options[:transport_options]['is_windows']
147
+ machine_for(machine_spec, machine_options)
148
+ else
149
+ machine_for(machine_spec, machine_options_for)
150
+ end
138
151
  end
139
152
 
140
153
  def destroy_machine(action_handler, machine_spec, machine_options)
@@ -227,10 +240,10 @@ class Chef
227
240
 
228
241
  def updated_ssh_machine_file_hash(new_machine_options, current_machine_options)
229
242
  log_info "updated_ssh_machine_file_hash --\nnew_machine_options = #{new_machine_options}\ncurrent_machine_options = #{current_machine_options}"
230
- if new_machine_options && new_machine_options['convergence_options']
243
+ if new_machine_options && new_machine_options['convergence_options']
231
244
  use_convergence_options = new_machine_options['convergence_options']
232
245
  else
233
- use_convergence_options = false
246
+ use_convergence_options = false
234
247
  end
235
248
 
236
249
  if new_machine_options && new_machine_options['transport_options']
@@ -289,7 +302,7 @@ class Chef
289
302
  host = host_for(opts)
290
303
 
291
304
  current_transport_options ||= {}
292
- current_transport_options['ssh_options'] ||= {}
305
+ current_transport_options['ssh_options'] ||= {}
293
306
  current_transport_options['ssh_options']['keys'] = [] unless current_transport_options['ssh_options']['keys']
294
307
  new_transport_options ||= {}
295
308
  new_transport_options['ssh_options'] ||= {}
@@ -397,7 +410,7 @@ class Chef
397
410
  log_info "@machine_options_for #{@machine_options_for}"
398
411
  return @machine_options_for
399
412
  else
400
- @machine_options_for ||= begin
413
+ @machine_options_for ||= begin
401
414
  _given_machine_options = given_machine_options.dup
402
415
  ret_val = false
403
416
  ret_val = symbolize_keys(_given_machine_options) if _given_machine_options
@@ -407,22 +420,56 @@ class Chef
407
420
  end
408
421
 
409
422
  def machine_for(machine_spec, machine_options)
410
- Chef::Provisioning::Machine::UnixMachine.new(machine_spec,
411
- transport_for(machine_options),
412
- convergence_strategy_for(machine_spec, machine_options))
423
+ if machine_options[:transport_options]['is_windows']
424
+ Chef::Provisioning::Machine::WindowsMachine.new(machine_spec, create_winrm_transport(machine_options),
425
+ convergence_strategy_for(machine_spec, machine_options))
426
+ else
427
+ Chef::Provisioning::Machine::UnixMachine.new(machine_spec,
428
+ transport_for(machine_options),
429
+ convergence_strategy_for(machine_spec, machine_options))
430
+ end
413
431
  end
414
432
 
415
433
  def transport_for(machine_options)
416
- Chef::Provisioning::Transport::SSH.new(@target_host, @username, @ssh_options_for_transport, @options, config)
434
+ if machine_options[:transport_options]['is_windows']
435
+ create_winrm_transport(machine_spec)
436
+ else
437
+ Chef::Provisioning::Transport::SSH.new(@target_host, @username, @ssh_options_for_transport, @options, config)
438
+ end
417
439
  end
418
440
 
419
441
  def convergence_strategy_for(machine_spec, machine_options)
420
- @unix_convergence_strategy ||= begin
421
- Chef::Provisioning::ConvergenceStrategy::InstallCached.new(machine_options[:convergence_options],
422
- config)
442
+ if machine_options[:transport_options]['is_windows']
443
+ @windows_convergence_strategy ||= begin
444
+ Chef::Provisioning::ConvergenceStrategy::InstallMsi.
445
+ new(machine_options[:convergence_options], config)
446
+ end
447
+ else
448
+ @unix_convergence_strategy ||= begin
449
+ Chef::Provisioning::ConvergenceStrategy::InstallCached.new(machine_options[:convergence_options],
450
+ config)
451
+ end
423
452
  end
424
453
  end
425
454
 
455
+ def create_winrm_transport(machine_options)
456
+ # forwarded_ports = machine_options[:transport_options]['forwarded_ports']
457
+
458
+ # TODO IPv6 loopback? What do we do for that?
459
+ hostname = machine_options[:transport_options]['host'] || '127.0.0.1'
460
+ port = machine_options[:transport_options]['port'] || 5985
461
+ # port = forwarded_ports[port] if forwarded_ports[port]
462
+ endpoint = "http://#{hostname}:#{port}/wsman"
463
+ type = :plaintext
464
+ options = {
465
+ :user => machine_options[:transport_options]['user'] || 'vagrant',
466
+ :pass => machine_options[:transport_options]['password'] || 'vagrant',
467
+ :disable_sspi => true
468
+ }
469
+
470
+ Chef::Provisioning::Transport::WinRM.new(endpoint, type, options, config)
471
+ end
472
+
426
473
  # def create_ssh_transport(machine_options)
427
474
  def ssh_options_for(given_ssh_options)
428
475
  machine_ssh_options = stringify_keys(given_ssh_options)
@@ -1,7 +1,7 @@
1
1
  class Chef
2
2
  module Provisioning
3
3
  module SshDriver
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zack Zondlo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-provisioning
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.4.1
106
+ rubygems_version: 2.4.4
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Provisioner for managing servers using ssh in Chef Provisioning.