hocho 0.3.2 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/hocho.gemspec +1 -1
- data/lib/hocho/drivers/ssh_base.rb +28 -17
- data/lib/hocho/host.rb +23 -4
- data/lib/hocho/property_providers/ruby_script.rb +27 -0
- data/lib/hocho/version.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f5398ffdb759cbfa7f06c5d388d5fa4b5455e81229f7546a302f9a97d9aeb8d
|
4
|
+
data.tar.gz: d07ddf5a3b23e81ba9b9d2eda67a909c3a4e84bd2a60a69bffcd682cad7db1e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e41c1eaa65f335385d5dead37cd1784500576f4ad3dfbb39e316771d28517b909097fafa687799e80067d2568a83ada90baa1db2e9030c3bcc6ddaca30020da
|
7
|
+
data.tar.gz: fdb35fd1103394c48602a766db80bcc90bec1777fb6d62dc562aebf0be2dfe6f73e3af6618679547d91ab92a07626a0e8c1616033e28f32e7017f5aa72deb31f
|
data/README.md
CHANGED
@@ -27,18 +27,30 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
$ gem install hocho
|
29
29
|
|
30
|
-
##
|
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
|
```
|
data/hocho.gemspec
CHANGED
@@ -71,7 +71,12 @@ module Hocho
|
|
71
71
|
|
72
72
|
temporary_passphrase = SecureRandom.base64(129).chomp
|
73
73
|
|
74
|
-
|
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
|
@@ -104,30 +109,36 @@ module Hocho
|
|
104
109
|
end
|
105
110
|
|
106
111
|
def set_ssh_output_hook(c)
|
107
|
-
|
108
|
-
|
109
|
-
|
112
|
+
check = ->(prefix, data, buf) do
|
113
|
+
data = buf + data unless buf.empty?
|
114
|
+
return if data.empty?
|
115
|
+
|
110
116
|
lines = data.lines
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
(
|
117
|
-
puts "#{prefix} #{line}"
|
118
|
-
end
|
119
|
-
buf.replace([])
|
117
|
+
|
118
|
+
# If data is not NL-terminated, its last line is carried over to next check.call
|
119
|
+
if lines.last.end_with?("\n")
|
120
|
+
buf.clear
|
121
|
+
else
|
122
|
+
buf.replace(lines.pop)
|
120
123
|
end
|
121
|
-
|
122
|
-
|
124
|
+
|
125
|
+
lines.each do |line|
|
126
|
+
puts "#{prefix}#{line}"
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
130
|
+
outbuf, errbuf = +"", +""
|
131
|
+
outpre, errpre = "[#{host.name}] ", "[#{host.name}/ERR] "
|
132
|
+
|
126
133
|
c.on_data do |c, data|
|
127
|
-
check.call
|
134
|
+
check.call outpre, data, outbuf
|
128
135
|
end
|
129
136
|
c.on_extended_data do |c, _, data|
|
130
|
-
check.call
|
137
|
+
check.call errpre, data, errbuf
|
138
|
+
end
|
139
|
+
c.on_close do
|
140
|
+
puts "#{outpre}#{outbuf}" unless outbuf.empty?
|
141
|
+
puts "#{errpre}#{errbuf}" unless errbuf.empty?
|
131
142
|
end
|
132
143
|
end
|
133
144
|
|
data/lib/hocho/host.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'hocho/utils/symbolize'
|
2
2
|
require 'hashie'
|
3
3
|
require 'net/ssh'
|
4
|
+
require 'net/ssh/proxy/jump'
|
4
5
|
require 'net/ssh/proxy/command'
|
5
6
|
|
6
7
|
module Hocho
|
@@ -106,7 +107,7 @@ module Hocho
|
|
106
107
|
when :encryption
|
107
108
|
[["Ciphers", [*value].join(?,)]]
|
108
109
|
when :compression
|
109
|
-
[["Compression", value]]
|
110
|
+
[["Compression", value ? 'yes' : 'no']]
|
110
111
|
when :compression_level
|
111
112
|
[["CompressionLevel", value]]
|
112
113
|
when :timeout
|
@@ -150,6 +151,8 @@ module Hocho
|
|
150
151
|
[["Port", value]]
|
151
152
|
when :proxy
|
152
153
|
case value
|
154
|
+
when Net::SSH::Proxy::Jump
|
155
|
+
[["ProxyJump", value.jump_proxies]]
|
153
156
|
when Net::SSH::Proxy::Command
|
154
157
|
[["ProxyCommand", value.command_line_template]]
|
155
158
|
when false
|
@@ -163,8 +166,17 @@ module Hocho
|
|
163
166
|
[["User", value]]
|
164
167
|
when :user_known_hosts_file
|
165
168
|
[["UserKnownHostsFile", value]]
|
166
|
-
when :
|
167
|
-
|
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
|
168
180
|
end
|
169
181
|
end.compact.map do |keyval|
|
170
182
|
keyval.join(separator)
|
@@ -198,7 +210,14 @@ module Hocho
|
|
198
210
|
def make_ssh_connection
|
199
211
|
alt = false
|
200
212
|
begin
|
201
|
-
|
213
|
+
# A workaround for a bug on net-ssh: https://github.com/net-ssh/net-ssh/issues/764
|
214
|
+
# :strict_host_key_checking is translated from ssh config. However, Net::SSH.start does not accept
|
215
|
+
# the option as valid one. Remove this part when net-ssh fixes the bug.
|
216
|
+
options = ssh_options
|
217
|
+
unless Net::SSH::VALID_OPTIONS.include?(:strict_host_key_checking)
|
218
|
+
options.delete(:strict_host_key_checking)
|
219
|
+
end
|
220
|
+
Net::SSH.start(name, nil, options)
|
202
221
|
rescue Net::SSH::Exception, Errno::ECONNREFUSED, Net::SSH::Proxy::ConnectError => e
|
203
222
|
raise if alt
|
204
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
|
data/lib/hocho/version.rb
CHANGED
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
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sorah (Shota Fukumori)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: hashie
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
111
|
+
description:
|
112
112
|
email:
|
113
113
|
- her@sorah.jp
|
114
114
|
executables:
|
@@ -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
|
@@ -152,7 +153,7 @@ homepage: https://github.com/sorah/hocho
|
|
152
153
|
licenses:
|
153
154
|
- MIT
|
154
155
|
metadata: {}
|
155
|
-
post_install_message:
|
156
|
+
post_install_message:
|
156
157
|
rdoc_options: []
|
157
158
|
require_paths:
|
158
159
|
- lib
|
@@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
169
|
version: '0'
|
169
170
|
requirements: []
|
170
171
|
rubygems_version: 3.1.2
|
171
|
-
signing_key:
|
172
|
+
signing_key:
|
172
173
|
specification_version: 4
|
173
174
|
summary: Server provisioning tool with itamae
|
174
175
|
test_files: []
|