-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_test.rb
executable file
·78 lines (63 loc) · 2.21 KB
/
package_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
require 'yaml'
require './vm_builder'
# For printing progress dots
STDOUT.sync = true
# To configure, copy the hash below to a file in this dir called options.yaml
# and alter appropriately
load_data = YAML.load_file('./options.yaml')
user_data = {
:user => 'admin',
:pass => 'changeme',
:url => 'https://foreman',
:hostname => "packaging#{`date '+%Y%m%d'`.chomp}",
:net_dev => 'br0',
:disk_size => '5G',
:hostgroup => 'Packaging',
:environment => 'production',
:compute_resource => 'Jade',
:architecture => 'x86_64',
:os_name => 'Debian',
:os_version => '7',
:location => 1, # No API calls to figure these out by name yet
:organisation => 2,
:delete => false,
}.merge load_data['options']
user_data[:delete] = true if ARGV[0] == "-d"
# Test connection port
final_port = load_data[:port] || 443
# Answers file:
answers = load_data[:answers] || "---\n"
# Any pull requests to try?
do_pull_requests = []
[:apache,:passenger,:puppet,:foreman,:foreman_proxy,:tftp].each do |mod|
unless load_data[mod].nil? or load_data[mod].empty?
do_pull_requests << [
"cd /tmp/f-i/#{mod.to_s}",
load_data[mod],
]
do_pull_requests.flatten!
end
end
# These will be joined with "&&" and executed over SSH
setup_commands = [
"echo -en 'Puppet version: ' && puppet --version",
"rm -rf /tmp/f-i",
"git clone -b develop --recursive https://github.com/theforeman/foreman-installer /tmp/f-i",
do_pull_requests,
"echo -e \"#{answers.to_yaml}\" > /tmp/f-i/foreman_installer/answers.yaml",
"echo include foreman_installer | puppet apply -v --modulepath /tmp/f-i --show_diff",
].flatten
### Code starts here ###
vm_builder = VmBuilder.new(user_data)
# Check Foreman is alive
vm_builder.check_connection
# build the host (if required)
vm_builder.check_and_create_host
# Monitor build status
vm_builder.wait_for_connection
# Log in and setup up Foreman
vm_builder.ssh_setup(setup_commands)
# Test if the new foreman instance is operational
protocol = final_port == 443 ? 'https' : 'http'
VmBuilder.new({:url => "#{protocol}://#{vm_builder.ip}:#{final_port}"}).check_connection