mofa 0.4.2 → 0.5.0
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 +4 -4
- data/lib/mofa/provision_cmd.rb +73 -57
- data/lib/mofa/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2731aa873c3d661b23a5c8bc92ec3809b5953db1
|
4
|
+
data.tar.gz: ccb852563643940df098c745947413007f91eee5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e05ebdb1799829e9bcb4a95bafa9100de7f741ff19b1822a1347448f7d10b6d39691337fd20db82750753dcb3d17792d0c6cd57b7faf209788a5aa64d862543
|
7
|
+
data.tar.gz: cdb0efffafd560b2c74c44fe461323bf6ff97d19a719eed6c3ef6c8d8362b3ec8ca68b5f6892dc0ba585cfa13c2d386697b71576227633d50373563ca40e7e4b
|
data/lib/mofa/provision_cmd.rb
CHANGED
@@ -84,14 +84,14 @@ class ProvisionCmd < MofaCmd
|
|
84
84
|
solo_rb = <<-"EOF"
|
85
85
|
cookbook_path [ "#{solo_dir}/cookbooks" ]
|
86
86
|
data_bag_path "#{solo_dir}/data_bags"
|
87
|
-
log_level :info
|
88
|
-
log_location "#{solo_dir}/log"
|
89
87
|
verify_api_cert true
|
90
88
|
EOF
|
91
89
|
|
92
90
|
file.write(solo_rb)
|
93
91
|
end
|
94
92
|
end
|
93
|
+
# log_level :info
|
94
|
+
# log_location "#{solo_dir}/log"
|
95
95
|
|
96
96
|
def create_node_json(sftp, hostname, solo_dir, attributes_map)
|
97
97
|
puts "Remotely creating \"#{solo_dir}/node.json\" on #{hostname}..."
|
@@ -160,67 +160,83 @@ class ProvisionCmd < MofaCmd
|
|
160
160
|
sftp.upload!("#{cookbook.pkg_dir}/#{cookbook.pkg_name}", "#{solo_dir}/#{cookbook.pkg_name}")
|
161
161
|
puts 'OK.'
|
162
162
|
|
163
|
-
#
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
163
|
+
File.open("#{cookbook.pkg_dir}/log", 'w') do |log_file|
|
164
|
+
# Do it -> Execute the chef-solo run!
|
165
|
+
begin
|
166
|
+
begin
|
167
|
+
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: Mofa::Config.config['ssh_port'], use_agent: false, verbose: :error) do |ssh|
|
168
|
+
puts "Remotely unpacking Cookbook Package #{cookbook.pkg_name}... "
|
169
|
+
ssh.exec!("cd #{solo_dir}; tar xvfz #{cookbook.pkg_name}") do |_ch, _stream, line|
|
170
|
+
puts line if Mofa::CLI.option_debug
|
171
|
+
log_file.write(line) if Mofa::CLI.option_debug
|
172
|
+
end
|
173
|
+
puts 'OK.'
|
174
|
+
end
|
175
|
+
rescue StandardError => e
|
176
|
+
status_msg = "ERROR: Unpacking cookbook archive on remote host #{hostname} failed (#{e.message})!"
|
177
|
+
chef_solo_runs[hostname].store('status', 'FAIL')
|
178
|
+
chef_solo_runs[hostname].store('status_msg', status_msg)
|
179
|
+
puts status_msg
|
180
|
+
log_file.write(status_msg)
|
181
|
+
raise e
|
182
|
+
end
|
183
|
+
begin
|
184
|
+
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: Mofa::Config.config['ssh_port'], use_agent: false, verbose: :error) do |ssh|
|
185
|
+
puts "Remotely running chef-solo -c #{solo_dir}/solo.rb -j #{solo_dir}/node.json"
|
186
|
+
chef_run_exit_code = 0
|
187
|
+
ssh.exec!("sudo chef-solo -c #{solo_dir}/solo.rb -j #{solo_dir}/node.json") do |_ch, _stream, line|
|
188
|
+
puts line if Mofa::CLI.option_verbose || Mofa::CLI.option_debug
|
189
|
+
log_file.write(line)
|
190
|
+
chef_run_exit_code = 1 if line =~ /Chef run process exited unsuccessfully/
|
191
|
+
end
|
192
|
+
raise 'Chef run process exited unsuccessfully' if chef_run_exit_code != 0
|
193
|
+
chef_solo_runs[hostname].store('status', 'SUCCESS')
|
194
|
+
chef_solo_runs[hostname].store('status_msg', '')
|
195
|
+
puts 'Chef-solo run was a SUCCESS!'
|
196
|
+
log_file.write('chef-solo run: SUCCESS')
|
197
|
+
end
|
198
|
+
rescue StandardError => e
|
199
|
+
status_msg = "ERROR: Chef-solo run on #{hostname} FAILED! (#{e.message})"
|
200
|
+
chef_solo_runs[hostname].store('status', 'FAIL')
|
201
|
+
chef_solo_runs[hostname].store('status_msg', status_msg)
|
202
|
+
puts status_msg
|
203
|
+
log_file.write(status_msg)
|
204
|
+
raise e
|
205
|
+
end
|
206
|
+
rescue StandardError => e
|
207
|
+
log_file.write('chef-solo run: FAIL')
|
208
|
+
puts "ERRORS detected while provisioning #{hostname} (#{e.message})."
|
172
209
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
210
|
+
Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: Mofa::Config.config['ssh_port'], use_agent: false, verbose: :error) do |ssh|
|
211
|
+
snapshot_or_release = cookbook.is_a?(SourceCookbook) ? 'snapshot' : 'release'
|
212
|
+
out = ssh_exec!(ssh, "sudo chown -R #{Mofa::Config.config['ssh_user']}.#{Mofa::Config.config['ssh_user']} #{solo_dir}")
|
213
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
214
|
+
out = ssh_exec!(ssh, '[ -d /var/lib/mofa ] || sudo mkdir /var/lib/mofa')
|
215
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
216
|
+
out = ssh_exec!(ssh, "echo #{cookbook.name} | sudo tee /var/lib/mofa/last_cookbook_name")
|
217
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
218
|
+
out = ssh_exec!(ssh, "echo '#{snapshot_or_release}' | sudo tee /var/lib/mofa/last_cookbook_snapshot_or_release")
|
219
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
220
|
+
out = ssh_exec!(ssh, "echo #{cookbook.version} | sudo tee /var/lib/mofa/last_cookbook_version")
|
221
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
222
|
+
out = ssh_exec!(ssh, "echo #{chef_solo_runs[hostname]['status']} | sudo tee /var/lib/mofa/last_status")
|
223
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
224
|
+
out = ssh_exec!(ssh, "date '+%Y-%m-%d %H:%M:%S' | sudo tee /var/lib/mofa/last_timestamp")
|
225
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
226
|
+
out = ssh_exec!(ssh, "echo '#{solo_dir}/log' | sudo tee /var/lib/mofa/last_log")
|
227
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
228
|
+
out = ssh_exec!(ssh, "echo $(date '+%Y-%m-%d %H:%M:%S')': #{cookbook.name}@#{cookbook.version} (#{chef_solo_runs[hostname]['status']})' | sudo tee -a /var/lib/mofa/history")
|
229
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
230
|
+
out = ssh_exec!(ssh, "sudo find #{solo_dir} -type d | xargs chmod 700")
|
231
|
+
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
232
|
+
out = ssh_exec!(ssh, "sudo find #{solo_dir} -type f | xargs chmod 600")
|
179
233
|
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
180
|
-
puts out[1]
|
181
|
-
chef_solo_runs[hostname].store('status', 'FAIL')
|
182
|
-
chef_solo_runs[hostname].store('status_msg', out[1])
|
183
|
-
else
|
184
|
-
if Mofa::CLI.option_debug
|
185
|
-
out = ssh_exec!(ssh, "sudo cat #{solo_dir}/log")
|
186
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
187
|
-
puts out[1]
|
188
|
-
else
|
189
|
-
out = ssh_exec!(ssh, "sudo grep 'Chef Run' #{solo_dir}/log")
|
190
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
191
|
-
puts 'Done.'
|
192
|
-
end
|
193
|
-
chef_solo_runs[hostname].store('status', 'SUCCESS')
|
194
|
-
chef_solo_runs[hostname].store('status_msg', '')
|
195
234
|
end
|
196
|
-
snapshot_or_release = cookbook.is_a?(SourceCookbook) ? 'snapshot' : 'release'
|
197
|
-
out = ssh_exec!(ssh, "sudo chown -R #{Mofa::Config.config['ssh_user']}.#{Mofa::Config.config['ssh_user']} #{solo_dir}")
|
198
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
199
|
-
out = ssh_exec!(ssh, '[ -d /var/lib/mofa ] || sudo mkdir /var/lib/mofa')
|
200
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
201
|
-
out = ssh_exec!(ssh, "echo #{cookbook.name} | sudo tee /var/lib/mofa/last_cookbook_name")
|
202
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
203
|
-
out = ssh_exec!(ssh, "echo '#{snapshot_or_release}' | sudo tee /var/lib/mofa/last_cookbook_snapshot_or_release")
|
204
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
205
|
-
out = ssh_exec!(ssh, "echo #{cookbook.version} | sudo tee /var/lib/mofa/last_cookbook_version")
|
206
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
207
|
-
out = ssh_exec!(ssh, "echo #{chef_solo_runs[hostname]['status']} | sudo tee /var/lib/mofa/last_status")
|
208
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
209
|
-
out = ssh_exec!(ssh, "date '+%Y-%m-%d %H:%M:%S' | sudo tee /var/lib/mofa/last_timestamp")
|
210
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
211
|
-
out = ssh_exec!(ssh, "echo '#{solo_dir}/log' | sudo tee /var/lib/mofa/last_log")
|
212
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
213
|
-
out = ssh_exec!(ssh, "echo $(date '+%Y-%m-%d %H:%M:%S')': #{cookbook.name}@#{cookbook.version} (#{chef_solo_runs[hostname]['status']})' | sudo tee -a /var/lib/mofa/history")
|
214
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
215
|
-
out = ssh_exec!(ssh, "sudo find #{solo_dir} -type d | xargs chmod 700")
|
216
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
217
|
-
out = ssh_exec!(ssh, "sudo find #{solo_dir} -type f | xargs chmod 600")
|
218
|
-
puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
|
219
235
|
end
|
236
|
+
at_least_one_chef_solo_run_failed = true unless chef_solo_runs[hostname]['status'] == 'SUCCESS'
|
237
|
+
sftp.upload!("#{cookbook.pkg_dir}/log", "#{solo_dir}/log")
|
220
238
|
end
|
221
|
-
at_least_one_chef_solo_run_failed = true unless chef_solo_runs[hostname]['status'] == 'SUCCESS'
|
222
239
|
end
|
223
|
-
|
224
240
|
# ------- print out report
|
225
241
|
puts
|
226
242
|
puts '----------------------------------------------------------------------'
|
data/lib/mofa/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Birk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|