mofa 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mofa/provision_cmd.rb +29 -24
- data/lib/mofa/version.rb +1 -1
- metadata +1 -1
data/lib/mofa/provision_cmd.rb
CHANGED
@@ -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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
puts "
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
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
|
data/lib/mofa/version.rb
CHANGED