-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vagrantfile
114 lines (98 loc) · 3.51 KB
/
Vagrantfile
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
# 创建要创建的虚拟机清单
vm_list = [
{
:name => "slurm",
:eth1 => "192.168.88.101",
:mem => "2048",
:cpu => "2",
:sshport => 22231,
:box => "icode/slurm",
:box_version => "1.2",
:role => "slurm",
:is_service_node => true
},
{
:name => "login",
:eth1 => "192.168.88.102",
:mem => "2048",
:cpu => "2",
:sshport => 22232,
:box => "icode/slurm_compute",
:box_version => "1.1",
:role => "slurm",
:is_service_node => false
},
{
:name => "cn01",
:eth1 => "192.168.88.103",
:mem => "2048",
:cpu => "2",
:sshport => 22233,
:box => "icode/slurm_compute",
:box_version => "1.1",
:role => "slurm",
:is_service_node => false
},
{
:name => "scow",
:eth1 => "192.168.88.100",
:mem => "4096",
:cpu => "4",
:sshport => 22288,
:box => "icode/scow_blank",
:box_version => "1.2",
:role => "scow",
:is_service_node => false
}
]
Vagrant.configure("2") do |config|
config.vm.box_check_update = false
Encoding.default_external = 'UTF-8'
config.vm.boot_timeout= 600
config.ssh.username= "root"
config.ssh.password= "vagrant"
config.ssh.insert_key = true
vm_list.each do |item|
config.vm.define item[:name] do |vm_config|
vm_config.vm.box = item[:box]
vm_config.vm.hostname = item[:name]
vm_config.vm.box_version = item[:box_version ]
vm_config.vm.network "private_network", ip: item[:eth1]
# 禁用掉默认的SSH服务转发端口
vm_config.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", disabled: "true"
vm_config.vm.network "forwarded_port", guest: 22, host: item[:sshport]
vm_config.vm.provider "virtualbox" do |vb|
vb.memory = item[:mem];
vb.cpus = item[:cpu];
vb.name = item[:name];
end
# 添加hosts
vm_config.vm.provision "shell", inline: "sed -i '$d' /etc/hosts"
vm_list.each do |it|
vm_config.vm.provision "shell", inline: "echo " + it[:eth1] + " " + it[:name] + " >> /etc/hosts"
end
if item[:role]=="slurm"
vm_config.vm.provision "shell", path: "scripts/munge.sh"
if item[:is_service_node]
vm_config.vm.provision "shell", path: "scripts/slurm_server.sh"
vm_config.vm.provision "shell", path: "scripts/nfs_server.sh"
vm_config.vm.provision "shell", path: "scripts/ldap_server.sh"
vm_config.vm.provision "shell", path: "scripts/ldap_client.sh"
else
vm_config.vm.provision "shell", path: "scripts/slurm_client.sh"
vm_config.vm.provision "shell", path: "scripts/nfs_client.sh"
vm_config.vm.provision "shell", path: "scripts/ldap_client.sh"
end
elsif item[:role]=="scow"
vm_config.vm.provision "shell", inline: "ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''"
vm_list.each do |it|
vm_config.vm.provision "shell", inline: "sshpass -pvagrant ssh-copy-id -o StrictHostKeyChecking=no "+ it[:eth1]
end
vm_config.vm.provision "shell", path: "scripts/scow.sh"
vm_config.vm.provision "shell", inline: "echo -e '\033[32m请通过http://"+item[:eth1]+"/mis/init/进行初始化\n用户名/密码:demo_admin/demo_admin \033[0m'"
else
vm_config.vm.provision "shell", inline: "echo 主机角色设置有误:"+ item[:slurm]
end
end
end
end