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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/ssp/application/office_node.rb', line 28
def create(fqdn, *roles)
ip = "192.168.1.#{options[:iplastpart]}"
disk_size = options[:memory] * 20 / 1024
hostname = fqdn.split(".").first
run_list = roles.map { |r| r =~ /recipe\[(.*)\]/ ? $1 : "role[#{r}]" }
unless run_list.include? "role[chef-client]"
run_list.unshift "role[chef-client]"
end
vncpass = pwgen
rootpass = pwgen
say_status "Name: ", fqdn, :cyan
say_status "Memory: ", "#{options[:memory]}MB", :cyan
say_status "Disk: ", "#{disk_size}GB", :cyan
say_status "IP: ", ip, :cyan
say_status "VNC password: ", vncpass, :cyan
say_status "root password: ", rootpass, :cyan
say "\nRequesting server", :magenta
command = "bash -c '\n/root/bin/mkdomu.sh -m \#{options[:memory]} -d \#{disk_size} -v \#{vncpass} -p \#{rootpass} \#{hostname} \#{options[:iplastpart]}\nxm create /etc/xen/\#{hostname}.cfg\n'\n"
ssh_run "vanilla", command
say "\nServer ready, waiting 15 seconds to bootstrap."
sleep 15
say "\nBootstrapping #{shell.set_color(fqdn, :bold)}..."
command = "bash -c '\nmkdir -p /etc/chef\n\n(\ncat <<'EOP'\n127.0.0.1 localhost localhost.localdomain\n\#{ip} \#{fqdn} \#{fqdn.split(\".\").first}\n\n192.168.1.82 basil basil.sspti.me chef.sspti.me\nEOP\n) > /etc/hosts\n\n(\ncat <<'EOP'\n\#{IO.read(chef_config[:validation_key])}\nEOP\n) > /tmp/validation.pem\nawk NF /tmp/validation.pem > /etc/chef/validation.pem\nrm /tmp/validation.pem\n\n(\ncat <<'EOP'\nlog_level :info\nlog_location STDOUT\nchef_server_url \"\#{chef_config[:chef_server_url]}\"\nvalidation_client_name \"\#{chef_config[:validation_client_name]}\"\nEOP\n) > /etc/chef/client.rb\n\n(\ncat <<'EOP'\n\#{{ \"run_list\" => run_list }.to_json}\nEOP\n) > /etc/chef/first-boot.json\n\napt-get -y update\napt-get -y upgrade\n\n/usr/local/bin/chef-client -j /etc/chef/first-boot.json'\n"
begin
ssh_run ip, command, "root", rootpass
rescue Net::SSH::HostKeyMismatch => key_ex
key_ex.remember_host!
retry
end
end
|