-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vagrantfile
78 lines (65 loc) · 2.69 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# List of supported operating systems
SUPPORTED_OS = {
"debian" => {box: "debian/strech64", bootstrap_os: "debian", user: "vagrant"},
"ubuntu" => {box: "ubuntu/bionic64", bootstrap_os: "ubuntu", user: "vagrant"},
"centos" => {box: "centos/7", bootstrap_os: "centos", user: "vagrant"}
}
# Vagrant instance management
$os = "ubuntu"
$num_instances = 1
$instance_name_prefix = "istioctl"
$vm_memory = 1024
$vm_cpus = 1
$subnet = "10.0.4.1" # For 10.0.4.1X
$box = SUPPORTED_OS[$os][:box]
# Ansible provisioner
$playbook = "istioctl.yml"
# if $inventory is not set, try to use example
$inventory = File.join(File.dirname(__FILE__), "inventory") if ! $inventory
# if $inventory has a hosts file use it, otherwise copy over vars etc
# to where vagrant expects dynamic inventory to be.
if ! File.exist?(File.join(File.dirname($inventory), "hosts"))
$vagrant_ansible = File.join(File.dirname(__FILE__), ".vagrant", "provisioners", "ansible")
FileUtils.mkdir_p($vagrant_ansible) if ! File.exist?($vagrant_ansible)
if ! File.exist?(File.join($vagrant_ansible,"inventory"))
FileUtils.ln_s($inventory, File.join($vagrant_ansible,"inventory"))
end
end
Vagrant.configure("2") do |config|
# always use Vagrants insecure key
config.ssh.insert_key = false
config.ssh.username = SUPPORTED_OS[$os][:user]
# Configure box
config.vm.box = $box
(1..$num_instances).each do |i|
config.vm.provider "virtualbox" do |vb|
vb.memory = $vm_memory
vb.cpus = $vm_cpus
end
config.vm.define vm_name = "%s%02d" % [$instance_name_prefix, i] do |server|
config.vm.hostname = vm_name
server.vm.network "private_network", ip: "#{$subnet}#{i}"
# Provision
config.vm.provision "shell", path: "provision.sh"
# config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "/home/vagrant/.ssh/authorized_keys"
# Only execute the Ansible provisioner when all the machines are up and ready
if i == $num_instances
config.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = $playbook
if File.exist?(File.join(File.dirname($inventory), "hosts"))
ansible.inventory_path = $inventory
end
ansible.become = true
ansible.limit = "all"
ansible.host_key_checking = false
ansible.groups = {
"istioctl" => ["#{$instance_name_prefix}0[1:#{$num_instances}]"]
}
end
end
end
end
end