-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
68 lines (56 loc) · 1.92 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
parameters = {
"node_count" => 3,
"node_hostname_prefix" => "handev",
"node_ip_start" => "192.168.100.10",
"node_memory" => 1024,
"node_cpus" => 1
}
Vagrant.configure(2) do |config|
config.vm.box = "hanest/node"
config.vm.box_url = "file://hanest/packer/hanest-node-virtualbox.box"
config.ssh.username = "hanest"
config.ssh.password = "theperfectnestforyourcontainers"
config.ssh.insert_key = true
config.vm.box_check_update = false
config.vm.synced_folder ".", "/vagrant", disabled: true
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = false
config.hostmanager.include_offline = false
config.hostmanager.ip_resolver = proc do |vm, _resolving_vm|
`VBoxManage guestproperty get #{vm.id} '/VirtualBox/GuestInfo/Net/1/V4/IP'`.split[1] if vm.id
end
hostvars, nodes = {}, []
(1..parameters["node_count"]).each do |n|
hostname = "%s%02d" % [parameters["node_hostname_prefix"], n]
ip = parameters["node_ip_start"] + "#{n}"
last = (n >= parameters["node_count"])
config.vm.define hostname, primary: last do |node|
node.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--cpus", parameters["node_cpus"]]
vb.customize ["modifyvm", :id, "--memory", parameters["node_memory"]]
end
node.vm.hostname = hostname
node.vm.network "private_network", :ip => ip
nodes << hostname
hostvars.merge!({
hostname => {
"private_ipv4" => ip,
"public_ipv4" => ip,
"role" => "node"
}
})
if last
node.vm.provision :hostmanager
node.vm.provision "ansible" do |ansible|
ansible.playbook = 'hanest/playbooks/node.yml'
# ansible.raw_arguments = ["-t setup"]
ansible.limit = 'all'
ansible.host_vars = hostvars
end
end
end
end
end