mofa 0.3.39 → 0.3.40

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.
@@ -1,5 +1,23 @@
1
1
  Metrics/LineLength:
2
2
  Enabled: false
3
3
 
4
+ Metrics/MethodLength:
5
+ Enabled: false
6
+
7
+ Metrics/ClassLength:
8
+ Enabled: false
9
+
10
+ Metrics/AbcSize:
11
+ Enabled: false
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Enabled: false
15
+
16
+ Metrics/PerceivedComplexity:
17
+ Enabled: false
18
+
4
19
  Style/Encoding:
5
20
  Enabled: false
21
+
22
+ Style/Documentation:
23
+ Enabled: false
@@ -58,10 +58,10 @@ class ProvisionCmd < MofaCmd
58
58
 
59
59
  def prepare_host(hostname, host_index, solo_dir)
60
60
  puts
61
- puts "----------------------------------------------------------------------"
62
- puts "Chef-Solo on Host #{hostname} (#{host_index}/#{hostlist.list.length.to_s})"
63
- puts "----------------------------------------------------------------------"
64
- Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], :keys => [Mofa::Config.config['ssh_keyfile']], :port => Mofa::Config.config['ssh_port'], :verbose => :error) do |ssh|
61
+ puts '----------------------------------------------------------------------'
62
+ puts "Chef-Solo on Host #{hostname} (#{host_index}/#{hostlist.list.length})"
63
+ puts '----------------------------------------------------------------------'
64
+ Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: Mofa::Config.config['ssh_port'], 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}")
@@ -79,8 +79,8 @@ class ProvisionCmd < MofaCmd
79
79
  end
80
80
 
81
81
  def create_solo_rb(sftp, hostname, solo_dir)
82
- puts "Remotely creating \"#{solo_dir}/solo.rb\""
83
- sftp.file.open("#{solo_dir}/solo.rb", "w") do |file|
82
+ puts "Remotely creating \"#{solo_dir}/solo.rb\" on #{hostname}..."
83
+ sftp.file.open("#{solo_dir}/solo.rb", 'w') do |file|
84
84
  solo_rb = <<-"EOF"
85
85
  cookbook_path [ "#{solo_dir}/cookbooks" ]
86
86
  data_bag_path "#{solo_dir}/data_bags"
@@ -94,20 +94,20 @@ class ProvisionCmd < MofaCmd
94
94
  end
95
95
 
96
96
  def create_node_json(sftp, hostname, solo_dir, attributes_map)
97
- puts "Remotely creating \"#{solo_dir}/node.json\""
97
+ puts "Remotely creating \"#{solo_dir}/node.json\" on #{hostname}..."
98
98
  node_json = {}
99
99
  node_json.store('run_list', runlist_map.mp[hostname])
100
100
  attributes_map.mp[hostname].each do |key, value|
101
101
  node_json.store(key, value)
102
102
  end
103
103
 
104
- sftp.file.open("#{solo_dir}/node.json", "w") do |file|
104
+ sftp.file.open("#{solo_dir}/node.json", 'w') do |file|
105
105
  file.write(JSON.pretty_generate(node_json))
106
106
  end
107
107
  end
108
108
 
109
109
  def create_data_bags(sftp, hostname, solo_dir)
110
- puts "Remotely creating data_bags items..."
110
+ puts "Remotely creating data_bags items on #{hostname}..."
111
111
  if File.directory?("#{cookbook.source_dir}/data_bags")
112
112
  Dir.entries("#{cookbook.source_dir}/data_bags/").each do |data_bag|
113
113
  next if data_bag =~ /^\.\.?$/
@@ -115,7 +115,7 @@ class ProvisionCmd < MofaCmd
115
115
  Dir.entries("#{cookbook.source_dir}/data_bags/#{data_bag}").select { |f| f.match(/\.json$/) }.each do |data_bag_item|
116
116
  puts "Uploading data_bag_item #{data_bag_item}... "
117
117
  sftp.upload!("#{cookbook.source_dir}/data_bags/#{data_bag}/#{data_bag_item}", "#{solo_dir}/data_bags/#{data_bag}/#{data_bag_item}")
118
- puts "OK."
118
+ puts 'OK.'
119
119
  end
120
120
  end
121
121
  end
@@ -132,10 +132,10 @@ class ProvisionCmd < MofaCmd
132
132
  chef_solo_runs = {}
133
133
  host_index = 0
134
134
  hostlist.list.each do |hostname|
135
- host_index = host_index + 1
135
+ host_index += 1
136
136
  chef_solo_runs.store(hostname, {})
137
137
 
138
- unless (options.key?('ignore_ping') && options[:ignore_ping] == true)
138
+ unless options.key?('ignore_ping') && options[:ignore_ping] == true
139
139
  unless host_avail?(hostname)
140
140
  chef_solo_runs[hostname].store('status', 'UNAVAIL')
141
141
  chef_solo_runs[hostname].store('status_msg', "Host #{hostname} unreachable.")
@@ -146,8 +146,7 @@ class ProvisionCmd < MofaCmd
146
146
 
147
147
  prepare_host(hostname, host_index, solo_dir)
148
148
 
149
- Net::SFTP.start(hostname, Mofa::Config.config['ssh_user'], :keys => [Mofa::Config.config['ssh_keyfile']], :port => Mofa::Config.config['ssh_port'], :verbose => :error) do |sftp|
150
-
149
+ Net::SFTP.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: Mofa::Config.config['ssh_port'], verbose: :error) do |sftp|
151
150
  # remotely creating solo.rb
152
151
  create_solo_rb(sftp, hostname, solo_dir)
153
152
 
@@ -159,18 +158,17 @@ class ProvisionCmd < MofaCmd
159
158
 
160
159
  puts "Uploading Package #{cookbook.pkg_name}... "
161
160
  sftp.upload!("#{cookbook.pkg_dir}/#{cookbook.pkg_name}", "#{solo_dir}/#{cookbook.pkg_name}")
162
- puts "OK."
161
+ puts 'OK.'
163
162
 
164
163
  # Do it -> Execute the chef-solo run!
165
- Net::SSH.start(hostname, Mofa::Config::config['ssh_user'], :keys => [Mofa::Config::config['ssh_keyfile']], :port => Mofa::Config.config['ssh_port'], :verbose => :error) do |ssh|
166
-
164
+ Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: Mofa::Config.config['ssh_port'], verbose: :error) do |ssh|
167
165
  puts "Remotely unpacking Cookbook Package #{cookbook.pkg_name}... "
168
166
  out = ssh_exec!(ssh, "cd #{solo_dir}; tar xvfz #{cookbook.pkg_name}")
169
167
  if out[0] != 0
170
168
  puts "ERROR (#{out[0]}): #{out[2]}"
171
169
  puts out[1]
172
170
  else
173
- puts "OK."
171
+ puts 'OK.'
174
172
  end
175
173
 
176
174
  puts "Remotely running chef-solo -c #{solo_dir}/solo.rb -j #{solo_dir}/node.json"
@@ -183,14 +181,14 @@ class ProvisionCmd < MofaCmd
183
181
  chef_solo_runs[hostname].store('status', 'FAIL')
184
182
  chef_solo_runs[hostname].store('status_msg', out[1])
185
183
  else
186
- unless Mofa::CLI::option_debug
187
- out = ssh_exec!(ssh, "sudo grep 'Chef Run' #{solo_dir}/log")
188
- puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
189
- puts "Done."
190
- else
184
+ if Mofa::CLI.option_debug
191
185
  out = ssh_exec!(ssh, "sudo cat #{solo_dir}/log")
192
186
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
193
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.'
194
192
  end
195
193
  chef_solo_runs[hostname].store('status', 'SUCCESS')
196
194
  chef_solo_runs[hostname].store('status_msg', '')
@@ -208,15 +206,16 @@ class ProvisionCmd < MofaCmd
208
206
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
209
207
  out = ssh_exec!(ssh, "echo #{chef_solo_runs[hostname]['status']} | sudo tee /var/lib/mofa/last_status")
210
208
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
211
- out = ssh_exec!(ssh, "echo '#!/bin/bash' | sudo tee /usr/bin/mofa_log && echo 'cat #{solo_dir}/log' | sudo tee -a /usr/bin/mofa_log && sudo chmod 755 /usr/bin/mofa_log")
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
212
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
213
- out = ssh_exec!(ssh, "date '+%Y-%m-%d %H:%M:%S' | sudo tee -a /var/lib/mofa/last_timestamp")
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
214
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
215
215
  out = ssh_exec!(ssh, "sudo find #{solo_dir} -type d | xargs chmod 700")
216
216
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
217
217
  out = ssh_exec!(ssh, "sudo find #{solo_dir} -type f | xargs chmod 600")
218
218
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
219
-
220
219
  end
221
220
  end
222
221
  at_least_one_chef_solo_run_failed = true unless chef_solo_runs[hostname]['status'] == 'SUCCESS'
@@ -224,10 +223,10 @@ class ProvisionCmd < MofaCmd
224
223
 
225
224
  # ------- print out report
226
225
  puts
227
- puts "----------------------------------------------------------------------"
228
- puts "Chef-Solo Run REPORT"
229
- puts "----------------------------------------------------------------------"
230
- puts "Chef-Solo has been run on #{chef_solo_runs.keys.length.to_s} hosts."
226
+ puts '----------------------------------------------------------------------'
227
+ puts 'Chef-Solo Run REPORT'
228
+ puts '----------------------------------------------------------------------'
229
+ puts "Chef-Solo has been run on #{chef_solo_runs.keys.length} hosts."
231
230
 
232
231
  chef_solo_runs.each do |hostname, content|
233
232
  status_msg = ''
@@ -235,18 +234,12 @@ class ProvisionCmd < MofaCmd
235
234
  puts "#{content['status']}: #{hostname} #{status_msg}"
236
235
  end
237
236
 
238
- exit_code = 0
239
- if at_least_one_chef_solo_run_failed
240
- exit_code = 1
241
- end
242
-
237
+ exit_code = at_least_one_chef_solo_run_failed ? 1 : 0
243
238
  puts "Exiting with exit code #{exit_code}."
244
239
 
245
240
  if exit_code != 0
246
241
  raise Thor::Error, "Chef client exited with non zero exit code: #{exit_code}"
247
242
  end
248
243
  exit_code
249
-
250
244
  end
251
-
252
245
  end
@@ -1,3 +1,3 @@
1
1
  module Mofa
2
- VERSION = '0.3.39'
2
+ VERSION = '0.3.40'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.39
4
+ version: 0.3.40
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-19 00:00:00.000000000 Z
12
+ date: 2017-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec