hocho 0.3.4 → 0.3.5

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
  SHA256:
3
- metadata.gz: 0fb6d2cfd588c821f79b52d3db9bf0fa13966d9304f91484db673ae3bd73b38b
4
- data.tar.gz: 253e0bb1b7cf9ce818807dd79bba5464e1f0ef83fb8efc2cd031135ae74f0630
3
+ metadata.gz: 2f61962a1136d9599c8cecf5befa6700f5ae547847a2b38e3a4a3aaeba849438
4
+ data.tar.gz: ed1d9cb144c79c3589ecfef262d45e367c35c109d7d4280233e64e2f844dbe6a
5
5
  SHA512:
6
- metadata.gz: 3334806ae5b1bb5c44e292efab921fba893a72c587b4329d110766c116ff27f7febd9841aada054d77425886563c5fb2ca26a7c277e9d103673cc9c82d6a1615
7
- data.tar.gz: bfe51cf6ccafdfef4c74d1e13abd008a5f909fe81bdc3b6b9868a0dfb7105674c2f9e2484c512e24282899abc5064e5bb6340b93b861748e049a80d258690738
6
+ metadata.gz: c057b7c3a289dfbc0a9dac7bf294cec8807af1d26744ff098f76b963df4626763eabeec0a7482c0186c09c99656b5bbfdbbfea92ec7c2c4cdfa93f42149c4c25
7
+ data.tar.gz: 7423407b1f272b38ba82c31041e3010206a71f05c1d2b07a3dea40c9a49cf58ecc2b16473d3d07aa0fe648d2aadc6fdad59c299038c22840cefed169d8d9cdca
data/README.md CHANGED
@@ -27,18 +27,30 @@ Or install it yourself as:
27
27
 
28
28
  $ gem install hocho
29
29
 
30
- ## Setup
30
+ ## Usage
31
31
 
32
32
  ``` yaml
33
33
  # hocho.yml
34
34
  inventory_providers:
35
35
  file:
36
36
  path: './hosts'
37
+
37
38
  property_providers:
39
+ ## Provide default values to host properties (reverse_merge).
38
40
  - add_default:
39
41
  properties:
40
42
  blah: blahblah
41
43
  # preferred_driver: mitamae
44
+ attributes:
45
+ node_attributes_goes_here: hello
46
+
47
+ ## Run ruby script to mutate host properties
48
+ - ruby_script:
49
+ name: name-for-your-convenience # optional
50
+ script: 'host.properties[:hello] = Time.now.xmlschema'
51
+ ## or
52
+ # file: path/to/script.rb
53
+
42
54
  # driver_options:
43
55
  # mitamae:
44
56
  # mitamae_prepare_script: 'wget -O /usr/local/bin/mitamae https://...'
@@ -52,6 +64,8 @@ test.example.org:
52
64
  properties:
53
65
  # preferred_driver: bundler
54
66
  # preferred_driver: mitamae
67
+ attributes:
68
+ node_attributes_goes_here: hello
55
69
  run_list:
56
70
  - roles/app/default.rb
57
71
  ```
@@ -71,7 +71,12 @@ module Hocho
71
71
 
72
72
  temporary_passphrase = SecureRandom.base64(129).chomp
73
73
 
74
- derive = system(*%w(openssl enc -pbkdf2), in: File::NULL, out: File::NULL, err: [:child, :out]) ? %w(-pbkdf2) : []
74
+ local_supports_pbkdf2 = system(*%w(openssl enc -pbkdf2), in: File::NULL, out: File::NULL, err: [:child, :out])
75
+ remote_supports_pbkdf2 = begin
76
+ exitstatus, * = ssh_run("openssl enc -pbkdf2", error: false, &:eof!)
77
+ exitstatus == 0
78
+ end
79
+ derive = local_supports_pbkdf2 && remote_supports_pbkdf2 ? %w(-pbkdf2) : []
75
80
 
76
81
  encrypted_password = IO.pipe do |r,w|
77
82
  w.write temporary_passphrase
@@ -166,6 +166,17 @@ module Hocho
166
166
  [["User", value]]
167
167
  when :user_known_hosts_file
168
168
  [["UserKnownHostsFile", value]]
169
+ when :verify_host_key
170
+ case value
171
+ when :never
172
+ [["StrictHostKeyChecking", "no"]]
173
+ when :accept_new_or_local_tunnel
174
+ [["StrictHostKeyChecking", "accept-new"]]
175
+ when :accept_new
176
+ [["StrictHostKeyChecking", "accept-new"]]
177
+ when :always
178
+ [["StrictHostKeyChecking", "yes"]]
179
+ end
169
180
  end
170
181
  end.compact.map do |keyval|
171
182
  keyval.join(separator)
@@ -198,8 +209,15 @@ module Hocho
198
209
 
199
210
  def make_ssh_connection
200
211
  alt = false
212
+ # A workaround for a bug on net-ssh: https://github.com/net-ssh/net-ssh/issues/764
213
+ # :strict_host_key_checking is translated from ssh config. However, Net::SSH.start does not accept
214
+ # the option as valid one. Remove this part when net-ssh fixes the bug.
215
+ options = ssh_options
216
+ unless Net::SSH::VALID_OPTIONS.include?(:strict_host_key_checking)
217
+ options.delete(:strict_host_key_checking)
218
+ end
201
219
  begin
202
- Net::SSH.start(name, nil, ssh_options)
220
+ Net::SSH.start(name, nil, options)
203
221
  rescue Net::SSH::Exception, Errno::ECONNREFUSED, Net::SSH::Proxy::ConnectError => e
204
222
  raise if alt
205
223
  raise unless alternate_ssh_options_available?
@@ -0,0 +1,27 @@
1
+ module Hocho
2
+ module PropertyProviders
3
+ class RubyScript
4
+ def initialize(name: nil, script: nil, file: nil)
5
+ @template = case
6
+ when script
7
+ compile(script, "(#{name || 'ruby_script'})")
8
+ when file
9
+ compile(File.read(file), name ? "(#{name})" : file)
10
+ end
11
+ end
12
+
13
+ def determine(host)
14
+ @template.new(host).run
15
+ nil
16
+ end
17
+
18
+ private
19
+
20
+ Template = Struct.new(:host)
21
+
22
+ def compile(script, name)
23
+ binding.eval("Class.new(Template) { def run;\n#{script}\nend; }", name, 0)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Hocho
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hocho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - sorah (Shota Fukumori)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -142,6 +142,7 @@ files:
142
142
  - lib/hocho/property_providers.rb
143
143
  - lib/hocho/property_providers/add_default.rb
144
144
  - lib/hocho/property_providers/base.rb
145
+ - lib/hocho/property_providers/ruby_script.rb
145
146
  - lib/hocho/runner.rb
146
147
  - lib/hocho/utils/finder.rb
147
148
  - lib/hocho/utils/symbolize.rb