This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Vagrantfile.baremetal
127 lines (105 loc) · 4.68 KB
/
Vagrantfile.baremetal
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
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
116
117
118
119
120
121
122
123
124
125
126
127
# -*- mode: ruby -*-
# vi: set ft=ruby :
# This is a Vagrant to automatically provision a bootstrap node with a
# Chef server.
# See http://www.vagrantup.com/ for info on Vagrant.
require 'json'
base_dir = File.expand_path(File.dirname(File.realpath(__FILE__)))
json_file = Dir[File.join(base_dir,'*.json')]
if json_file.empty?
puts "No environment file found to parse. Please make sure at least one environment file exists."
exit
end
if json_file.length > 1
puts "More than one environment file found."
exit
end
file_name=File.basename(json_file.join(","))
chef_env = JSON.parse(File.read(json_file.join(",")))
bridge_if = chef_env["override_attributes"]["bcpc"]["bootstrap"]["pxe_interface"]
ip_address = chef_env["override_attributes"]["bcpc"]["bootstrap"]["server"]
env_name = chef_env["name"]
host_name = "bcpc-cluster-#{env_name}-bootstrap"
puts "Base dir : #{base_dir}"
puts "Json file : #{json_file}"
puts "Interface : #{bridge_if}"
puts "IP Address : #{ip_address}"
puts "Chef Env : #{env_name}"
puts "hostname : #{host_name}"
puts "File name : #{file_name}"
Vagrant.configure("2") do |config|
config.vm.define :bootstrap do |bootstrap|
bootstrap.vm.hostname = host_name
bootstrap.vm.network "public_network", :ip => ip_address, :bridge => bridge_if, auto_config: false
bootstrap.vm.provision :file, source: json_file.join(","), destination: "/home/vagrant/chef-bcpc/environments/#{file_name}"
# Chef provisioning
bootstrap.vm.provision "chef_solo" do |chef|
chef.environments_path = [[:vm,"environments"]]
chef.environment = env_name
chef.cookbooks_path = [[:vm,"cookbooks"]]
chef.roles_path = [[:vm,"roles"]]
chef.add_recipe("bcpc::bootstrap_network")
chef.log_level="debug"
chef.verbose_logging=true
chef.provisioning_path="/home/vagrant/chef-bcpc/"
end
# Chef provisioning
bootstrap.vm.provision "chef_solo" do |chef|
chef.environments_path = [[:vm,"environments"]]
chef.environment = env_name
chef.cookbooks_path = [[:vm,"cookbooks"]]
chef.roles_path = [[:vm,"roles"]]
chef.add_recipe("bcpc::bootstrap_knife")
chef.log_level="debug"
chef.verbose_logging=true
chef.provisioning_path="/home/vagrant/chef-bcpc/"
end
# Reconfigure chef-server
bootstrap.vm.provision :shell, :inline => "sudo chef-server-ctl reconfigure"
# Chef provisioning
bootstrap.vm.provision "chef_solo" do |chef|
chef.environments_path = [[:vm,"environments"]]
chef.environment = env_name
chef.cookbooks_path = [[:vm,"cookbooks"]]
chef.roles_path = [[:vm,"roles"]]
chef.add_recipe("bcpc::bootstrap_cleanup")
chef.log_level="debug"
chef.verbose_logging=true
chef.provisioning_path="/home/vagrant/chef-bcpc/"
end
# Rekey the admin user
bootstrap.vm.provision :shell, :inline => "cd /home/vagrant/chef-bcpc; sudo mv /etc/chef-server/admin.pem /tmp/old_admin.pem; sudo knife user reregister admin -u admin -k /tmp/old_admin.pem | sudo tee /etc/chef-server/admin.pem > /dev/null"
bootstrap.vm.provision :shell, :inline => "cd /home/vagrant/chef-bcpc; sudo knife environment from file environments/#{env_name}.json -u admin -k /etc/chef-server/admin.pem"
bootstrap.vm.provision :shell, :inline => "cd /home/vagrant/chef-bcpc; sudo chef-client -E #{env_name} -c .chef/knife.rb"
# Chef provisioning
bootstrap.vm.provision "chef_solo" do |chef|
chef.environments_path = [[:vm,"environments"]]
chef.environment = env_name
chef.cookbooks_path = [[:vm,"cookbooks"]]
chef.roles_path = [[:vm,"roles"]]
chef.add_recipe("bcpc::bootstrap_config")
chef.log_level="debug"
chef.verbose_logging=true
chef.provisioning_path="/home/vagrant/chef-bcpc/"
end
bootstrap.vm.provision :shell, :inline => "cd /home/vagrant/chef-bcpc; sudo chef-client -E #{env_name} -c .chef/knife.rb"
end
config.vm.box = "#{env_name}"
config.vm.box_url = "./GENERIC.box"
memory = ( ENV["BOOTSTRAP_VM_MEM"] or "4096" )
cpus = ( ENV["BOOTSTRAP_VM_CPUs"] or "2" )
config.vm.provider :virtualbox do |vb|
# Don't boot with headless mode
vb.gui = false
vb.name = host_name
vb.customize ["setproperty", "machinefolder", "#{base_dir}/#{env_name}"]
vb.customize ["modifyvm", :id, "--nictype2", "82543GC"]
vb.customize ["modifyvm", :id, "--memory", memory]
vb.customize ["modifyvm", :id, "--cpus", cpus]
vb.customize ["modifyvm", :id, "--largepages", "on"]
vb.customize ["modifyvm", :id, "--nestedpaging", "on"]
vb.customize ["modifyvm", :id, "--vtxvpid", "on"]
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
end