mofa 0.5.4 → 0.5.11
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.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/lib/mofa/attributes_map.rb +8 -2
- data/lib/mofa/cli.rb +5 -2
- data/lib/mofa/cmd_line_args.rb +25 -0
- data/lib/mofa/mofa_cmd.rb +1 -1
- data/lib/mofa/provision_cmd.rb +12 -12
- data/lib/mofa/released_cookbook.rb +13 -9
- data/lib/mofa/runlist_map.rb +2 -1
- data/lib/mofa/upload_cmd.rb +1 -1
- data/lib/mofa/version.rb +1 -1
- data/mofa.gemspec +2 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 53a589ffb32931662ca28a41fbd8081a4471db52287d6b792a1033b64221803e
|
4
|
+
data.tar.gz: 50920386da52fabe51ce55bf1dd4144ad49d9f7d26679d9d592da3ca1e9dca36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0aea4b5658276cfdae1bd83f72bbc705ea80b43bc87a15168d08f553912d1629c2a533bfb99895ef6d917420b728c5dfefa6ce391a7882627c5d0c373f7cd3d
|
7
|
+
data.tar.gz: ed15e04c4eabebfc08c66e303bb112f8757543ea3c5ec8c3cd5f9184a9b5715d6a1607205a8a5b172462b967da9be51b0b4211f71a52709ce8ec5ff4c650f225
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.6.6
|
data/lib/mofa/attributes_map.rb
CHANGED
@@ -47,10 +47,16 @@ class AttributesMap
|
|
47
47
|
elsif value.is_a?(Array)
|
48
48
|
new_attr_hash[key] = []
|
49
49
|
value.each do |value_item|
|
50
|
-
|
50
|
+
if value_item.is_a?(Hash)
|
51
|
+
new_attr_hash[key] = deep_parse(value, placeholder, content)
|
52
|
+
else
|
53
|
+
new_attr_hash[key].push(value_item.gsub(Regexp.new(Regexp.escape(placeholder)), content))
|
54
|
+
end
|
51
55
|
end
|
52
56
|
else
|
53
|
-
|
57
|
+
if value
|
58
|
+
new_attr_hash[key] = value.gsub(Regexp.new(Regexp.escape(placeholder)), content)
|
59
|
+
end
|
54
60
|
end
|
55
61
|
end
|
56
62
|
new_attr_hash
|
data/lib/mofa/cli.rb
CHANGED
@@ -19,6 +19,7 @@ module Mofa
|
|
19
19
|
method_option :ignore_ping, :type => :boolean, :aliases => '-p'
|
20
20
|
method_option :target, :type => :string, :aliases => '-t'
|
21
21
|
method_option :concrete_target, :type => :string, :aliases => '-T'
|
22
|
+
method_option :sshport, :type => :string, :aliases => '-P'
|
22
23
|
method_option :runlist, :type => :string, :aliases => '-o'
|
23
24
|
method_option :attributes, :type => :string, :aliases => '-j'
|
24
25
|
method_option :service_hostlist_url, :type => :string
|
@@ -47,12 +48,13 @@ module Mofa
|
|
47
48
|
cmd.options = options
|
48
49
|
|
49
50
|
cmd.prepare
|
50
|
-
cmd.execute
|
51
|
+
cmd.execute(options[:sshport])
|
51
52
|
cmd.cleanup
|
52
53
|
end
|
53
54
|
|
54
55
|
desc 'upload <cookbook>', 'package & upload cookbook into binrepo'
|
55
56
|
method_option :binrepo_host, :type => :string
|
57
|
+
method_option :binrepo_sshport, :type => :string
|
56
58
|
method_option :binrepo_ssh_user, :type => :string
|
57
59
|
method_option :binrepo_ssh_keyfile, :type => :string
|
58
60
|
|
@@ -67,7 +69,8 @@ module Mofa
|
|
67
69
|
cmd = UploadCmd.new(token, cookbook)
|
68
70
|
|
69
71
|
cmd.prepare
|
70
|
-
|
72
|
+
# FIXME: bring in the ssh-port in a different way
|
73
|
+
cmd.execute(22)
|
71
74
|
cmd.cleanup
|
72
75
|
end
|
73
76
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Mofa
|
2
|
+
class CmdLineArgs
|
3
|
+
def self.instance
|
4
|
+
@__instance__ ||= new
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@cmd_line_args = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def register(cmd_line_args)
|
12
|
+
@cmd_line_args = cmd_line_args
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(key)
|
16
|
+
raise "Cmd Line Arg with key #{key} does not exist!" unless @cmd_line_args.key?(key)
|
17
|
+
@cmd_line_args[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
def list
|
21
|
+
puts 'Comman Line Args:'
|
22
|
+
@cmd_line_args.inspect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/mofa/mofa_cmd.rb
CHANGED
data/lib/mofa/provision_cmd.rb
CHANGED
@@ -14,7 +14,7 @@ class ProvisionCmd < MofaCmd
|
|
14
14
|
cookbook.prepare
|
15
15
|
end
|
16
16
|
|
17
|
-
def execute
|
17
|
+
def execute(ssh_port = 22)
|
18
18
|
cookbook.execute
|
19
19
|
|
20
20
|
hostlist.retrieve
|
@@ -30,7 +30,7 @@ class ProvisionCmd < MofaCmd
|
|
30
30
|
|
31
31
|
puts "Hostlist after runlist filtering: #{hostlist.list.inspect}"
|
32
32
|
|
33
|
-
exit_code = run_chef_solo_on_hosts
|
33
|
+
exit_code = run_chef_solo_on_hosts(ssh_port)
|
34
34
|
|
35
35
|
exit_code
|
36
36
|
end
|
@@ -56,12 +56,12 @@ class ProvisionCmd < MofaCmd
|
|
56
56
|
host_available
|
57
57
|
end
|
58
58
|
|
59
|
-
def prepare_host(hostname, host_index, solo_dir)
|
59
|
+
def prepare_host(hostname, host_index, solo_dir, ssh_port = Mofa::Config.config['ssh_port'] )
|
60
60
|
puts
|
61
61
|
puts '----------------------------------------------------------------------'
|
62
62
|
puts "Chef-Solo on Host #{hostname} (#{host_index}/#{hostlist.list.length})"
|
63
63
|
puts '----------------------------------------------------------------------'
|
64
|
-
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port:
|
64
|
+
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
|
65
65
|
puts "Remotely creating solo_dir \"#{solo_dir}\" on host #{hostname}"
|
66
66
|
# remotely create the temp folder
|
67
67
|
out = ssh_exec!(ssh, "[ -d #{solo_dir} ] || mkdir #{solo_dir}")
|
@@ -121,13 +121,13 @@ class ProvisionCmd < MofaCmd
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
def run_chef_solo_on_hosts
|
124
|
+
def run_chef_solo_on_hosts(ssh_port = Mofa::Config.config['ssh_port'])
|
125
125
|
time = Time.new
|
126
126
|
# Create a temp working dir on the target host
|
127
127
|
solo_dir = '/var/tmp/' + time.strftime('%Y-%m-%d_%H%M%S')
|
128
128
|
puts
|
129
129
|
puts 'Chef-Solo Run started at ' + time.strftime('%Y-%m-%d %H:%M:%S')
|
130
|
-
puts "Will use ssh_user #{Mofa::Config.config['ssh_user']}, ssh_port #{
|
130
|
+
puts "Will use ssh_user #{Mofa::Config.config['ssh_user']}, ssh_port #{ssh_port} and ssh_key_file #{Mofa::Config.config['ssh_keyfile']}"
|
131
131
|
at_least_one_chef_solo_run_failed = false
|
132
132
|
chef_solo_runs = {}
|
133
133
|
host_index = 0
|
@@ -144,9 +144,9 @@ class ProvisionCmd < MofaCmd
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
prepare_host(hostname, host_index, solo_dir)
|
147
|
+
prepare_host(hostname, host_index, solo_dir, ssh_port)
|
148
148
|
|
149
|
-
Net::SFTP.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port:
|
149
|
+
Net::SFTP.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |sftp|
|
150
150
|
# remotely creating solo.rb
|
151
151
|
create_solo_rb(sftp, hostname, solo_dir)
|
152
152
|
|
@@ -164,7 +164,7 @@ class ProvisionCmd < MofaCmd
|
|
164
164
|
# Do it -> Execute the chef-solo run!
|
165
165
|
begin
|
166
166
|
begin
|
167
|
-
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port:
|
167
|
+
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
|
168
168
|
puts "Remotely unpacking Cookbook Package #{cookbook.pkg_name}... "
|
169
169
|
ssh.exec!("cd #{solo_dir}; tar xvfz #{cookbook.pkg_name}") do |_ch, _stream, line|
|
170
170
|
puts line if Mofa::CLI.option_debug
|
@@ -181,13 +181,13 @@ class ProvisionCmd < MofaCmd
|
|
181
181
|
raise e
|
182
182
|
end
|
183
183
|
begin
|
184
|
-
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port:
|
184
|
+
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
|
185
185
|
puts "Remotely running chef-solo -c #{solo_dir}/solo.rb -j #{solo_dir}/node.json"
|
186
186
|
chef_run_exit_code = 0
|
187
187
|
ssh.exec!("sudo chef-solo -c #{solo_dir}/solo.rb -j #{solo_dir}/node.json") do |_ch, _stream, line|
|
188
188
|
puts line if Mofa::CLI.option_verbose || Mofa::CLI.option_debug
|
189
189
|
log_file.write(line)
|
190
|
-
chef_run_exit_code = 1 if line =~ /Chef run process exited unsuccessfully/
|
190
|
+
chef_run_exit_code = 1 if line =~ /Chef run process exited unsuccessfully/ || line =~ /chef-solo: command not found/
|
191
191
|
end
|
192
192
|
raise 'Chef run process exited unsuccessfully' if chef_run_exit_code != 0
|
193
193
|
chef_solo_runs[hostname].store('status', 'SUCCESS')
|
@@ -207,7 +207,7 @@ class ProvisionCmd < MofaCmd
|
|
207
207
|
log_file.write('chef-solo run: FAIL')
|
208
208
|
puts "ERRORS detected while provisioning #{hostname} (#{e.message})."
|
209
209
|
end
|
210
|
-
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port:
|
210
|
+
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
|
211
211
|
snapshot_or_release = cookbook.is_a?(SourceCookbook) ? 'snapshot' : 'release'
|
212
212
|
out = ssh_exec!(ssh, "sudo chown -R #{Mofa::Config.config['ssh_user']}.#{Mofa::Config.config['ssh_user']} #{solo_dir}")
|
213
213
|
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
@@ -30,7 +30,7 @@ class ReleasedCookbook < Cookbook
|
|
30
30
|
set_cookbooks_url
|
31
31
|
end
|
32
32
|
|
33
|
-
def execute
|
33
|
+
def execute
|
34
34
|
package
|
35
35
|
end
|
36
36
|
|
@@ -65,16 +65,20 @@ class ReleasedCookbook < Cookbook
|
|
65
65
|
|
66
66
|
# Sync in mofa_secrets
|
67
67
|
if override_mofa_secrets
|
68
|
-
if File.directory?("#{override_mofa_secrets}/#{name}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
if File.directory?("#{override_mofa_secrets}/#{name}")
|
69
|
+
if File.directory?("#{override_mofa_secrets}/#{name}/cookbooks")
|
70
|
+
run "rsync -vr #{override_mofa_secrets}/#{name}/cookbooks/ #{pkg_dir}/tmp/cookbooks/"
|
71
|
+
if File.file?("#{override_mofa_secrets}/#{name}/.mofa.local.yml")
|
72
|
+
FileUtils.cp "#{override_mofa_secrets}/#{name}/.mofa.local.yml", "#{pkg_dir}/tmp/cookbooks/#{name}/"
|
73
|
+
end
|
74
|
+
if File.file?("#{override_mofa_secrets}/#{name}/.mofa.yml")
|
75
|
+
FileUtils.cp "#{override_mofa_secrets}/#{name}/.mofa.yml", "#{pkg_dir}/tmp/cookbooks/#{name}/"
|
76
|
+
end
|
77
|
+
else
|
78
|
+
run "rsync -vr #{override_mofa_secrets}/#{name}/ #{pkg_dir}/tmp/cookbooks/#{name}/"
|
75
79
|
end
|
76
80
|
else
|
77
|
-
|
81
|
+
say "Skipping non-existant mofa-secrets folder #{override_mofa_secrets}/#{name}"
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
data/lib/mofa/runlist_map.rb
CHANGED
@@ -44,9 +44,10 @@ class RunlistMap
|
|
44
44
|
# and so on
|
45
45
|
hostlist.list.each do |hostname|
|
46
46
|
cookbook.recipes.each do |recipe|
|
47
|
-
recipe_regex = "^#{recipe}[0-9]
|
47
|
+
recipe_regex = "^#{recipe}[0-9]*\\\."
|
48
48
|
if hostname.match(recipe_regex)
|
49
49
|
@mp.store(hostname, "recipe[#{cookbook.name}::#{recipe}]")
|
50
|
+
break
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
data/lib/mofa/upload_cmd.rb
CHANGED
data/lib/mofa/version.rb
CHANGED
data/mofa.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency "guard-minitest"
|
20
20
|
s.add_development_dependency "rake"
|
21
21
|
s.add_runtime_dependency "thor"
|
22
|
+
# s.add_runtime_dependency "ed25519"
|
23
|
+
# s.add_runtime_dependency "bcrypt_pbkdf"
|
22
24
|
s.add_runtime_dependency "json"
|
23
25
|
s.add_runtime_dependency "rest-client"
|
24
26
|
s.add_runtime_dependency "net-ssh"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mofa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Birk
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -202,6 +202,7 @@ extra_rdoc_files: []
|
|
202
202
|
files:
|
203
203
|
- ".gitignore"
|
204
204
|
- ".rubocop.yml"
|
205
|
+
- ".ruby-version"
|
205
206
|
- ".travis.yml"
|
206
207
|
- Gemfile
|
207
208
|
- Guardfile
|
@@ -213,6 +214,7 @@ files:
|
|
213
214
|
- lib/mofa.rb
|
214
215
|
- lib/mofa/attributes_map.rb
|
215
216
|
- lib/mofa/cli.rb
|
217
|
+
- lib/mofa/cmd_line_args.rb
|
216
218
|
- lib/mofa/config.rb
|
217
219
|
- lib/mofa/cookbook.rb
|
218
220
|
- lib/mofa/hostlist.rb
|
@@ -230,7 +232,7 @@ files:
|
|
230
232
|
homepage: https://github.com/pingworks/mofa
|
231
233
|
licenses: []
|
232
234
|
metadata: {}
|
233
|
-
post_install_message:
|
235
|
+
post_install_message:
|
234
236
|
rdoc_options: []
|
235
237
|
require_paths:
|
236
238
|
- lib
|
@@ -245,9 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
247
|
- !ruby/object:Gem::Version
|
246
248
|
version: '0'
|
247
249
|
requirements: []
|
248
|
-
|
249
|
-
|
250
|
-
signing_key:
|
250
|
+
rubygems_version: 3.0.3
|
251
|
+
signing_key:
|
251
252
|
specification_version: 4
|
252
253
|
summary: a lightweight remote chef-solo runner
|
253
254
|
test_files: []
|