mofa 0.3.15 → 0.3.16

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.
@@ -42,37 +42,39 @@ class ProvisionCmd < MofaCmd
42
42
  # This Code is Copy'n'Pasted from the old mofa tooling. Only to make the MVP work in time!!
43
43
  # This needs to be refactored ASAP.
44
44
 
45
+ def host_avail?(hostname)
46
+ host_available = false
47
+ puts "Pinging host #{hostname}..."
48
+ exit_status = system("ping -q -c 1 #{hostname} >/dev/null 2>&1")
49
+ if exit_status
50
+ puts " --> Host #{hostname} is available."
51
+ host_available = true
52
+ else
53
+ puts " --> Host #{hostname} is unavailable!"
54
+ end
55
+ host_available
56
+ end
57
+
45
58
  def prepare_host(hostname, host_index, solo_dir)
46
- prerequesits_met = false
47
59
  puts
48
60
  puts "----------------------------------------------------------------------"
49
61
  puts "Chef-Solo on Host #{hostname} (#{host_index}/#{hostlist.list.length.to_s})"
50
62
  puts "----------------------------------------------------------------------"
51
-
52
- puts "Pinging host #{hostname}..."
53
- exit_status = system("ping -q -c 1 #{hostname} >/dev/null 2>&1")
54
- unless exit_status then
55
- puts " --> Host #{hostname} is unavailable!"
56
- else
57
- puts " --> Host #{hostname} is available."
58
- prerequesits_met = true
59
- 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|
60
- puts "Remotely creating solo_dir \"#{solo_dir}\" on host #{hostname}"
61
- # remotely create the temp folder
62
- out = ssh_exec!(ssh, "[ -d #{solo_dir} ] || mkdir #{solo_dir}")
63
- puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
64
-
65
- # remotely create a data_bags folder structure on the target host
66
- if cookbook.instance_of?(SourceCookbook) and File.directory?("#{cookbook.source_dir}/data_bags")
67
- Dir.entries("#{cookbook.source_dir}/data_bags").select { |f| !f.match(/^\.\.?$/) }.each do |data_bag|
68
- puts "Remotely creating data_bags dir \"#{solo_dir}/data_bags/#{data_bag}\""
69
- out = ssh_exec!(ssh, "[ -d #{solo_dir}/data_bags/#{data_bag} ] || mkdir -p #{solo_dir}/data_bags/#{data_bag}")
70
- puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
71
- end
63
+ 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|
64
+ puts "Remotely creating solo_dir \"#{solo_dir}\" on host #{hostname}"
65
+ # remotely create the temp folder
66
+ out = ssh_exec!(ssh, "[ -d #{solo_dir} ] || mkdir #{solo_dir}")
67
+ puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
68
+
69
+ # remotely create a data_bags folder structure on the target host
70
+ if cookbook.instance_of?(SourceCookbook) and File.directory?("#{cookbook.source_dir}/data_bags")
71
+ Dir.entries("#{cookbook.source_dir}/data_bags").select { |f| !f.match(/^\.\.?$/) }.each do |data_bag|
72
+ puts "Remotely creating data_bags dir \"#{solo_dir}/data_bags/#{data_bag}\""
73
+ out = ssh_exec!(ssh, "[ -d #{solo_dir}/data_bags/#{data_bag} ] || mkdir -p #{solo_dir}/data_bags/#{data_bag}")
74
+ puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
72
75
  end
73
76
  end
74
77
  end
75
- prerequesits_met
76
78
  end
77
79
 
78
80
  def create_solo_rb(sftp, hostname, solo_dir)
@@ -139,12 +141,15 @@ class ProvisionCmd < MofaCmd
139
141
  hostlist.list.each do |hostname|
140
142
  host_index = host_index + 1
141
143
  chef_solo_runs.store(hostname, {})
142
- unless prepare_host(hostname, host_index, solo_dir)
144
+
145
+ unless host_avail?(hostname)
143
146
  chef_solo_runs[hostname].store('status', 'UNAVAIL')
144
147
  chef_solo_runs[hostname].store('status_msg', "Host #{hostname} unreachable.")
145
148
  next
146
149
  end
147
150
 
151
+ prepare_host(hostname, host_index, solo_dir)
152
+
148
153
  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|
149
154
 
150
155
  # remotely creating solo.rb
@@ -1,3 +1,3 @@
1
1
  module Mofa
2
- VERSION = "0.3.15"
2
+ VERSION = "0.3.16"
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.15
4
+ version: 0.3.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: