5 :virtualbox => { :name => 'elastic/ubuntu-16.04-x86_64', :version => '20180708.0.0' },
6 :libvirt => { :name => 'elastic/ubuntu-16.04-x86_64', :version=> '20180210.0.0'}
10 pdf = File.dirname(__FILE__) + '/config/default.yml'
11 if File.exist?(File.dirname(__FILE__) + '/config/pdf.yml')
12 pdf = File.dirname(__FILE__) + '/config/pdf.yml'
14 nodes = YAML.load_file(pdf)
16 # Inventory file creation
17 File.open(File.dirname(__FILE__) + "/inventory/hosts.ini", "w") do |inventory_file|
18 inventory_file.puts("[all:vars]\nansible_connection=ssh\nansible_ssh_user=vagrant\nansible_ssh_pass=vagrant\n\n[all]")
20 inventory_file.puts("#{node['name']}\tansible_ssh_host=#{node['ip']} ansible_ssh_port=22")
22 ['kube-master', 'kube-node', 'etcd', 'ovn-central', 'ovn-controller', 'virtlet'].each do|group|
23 inventory_file.puts("\n[#{group}]")
25 if node['roles'].include?("#{group}")
26 inventory_file.puts(node['name'])
30 inventory_file.puts("\n[k8s-cluster:children]\nkube-node\nkube-master")
33 provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
34 puts "[INFO] Provider: #{provider} "
36 if ENV['no_proxy'] != nil or ENV['NO_PROXY']
37 $no_proxy = ENV['NO_PROXY'] || ENV['no_proxy'] || "127.0.0.1,localhost"
39 $no_proxy += "," + node['ip']
41 $subnet = "192.168.121"
42 if provider == :virtualbox
45 # NOTE: This range is based on vagrant-libvirt network definition CIDR 192.168.121.0/27
47 $no_proxy += ",#{$subnet}.#{i}"
51 Vagrant.configure("2") do |config|
52 config.vm.box = box[provider][:name]
53 config.vm.box_version = box[provider][:version]
55 if ENV['http_proxy'] != nil and ENV['https_proxy'] != nil
56 if Vagrant.has_plugin?('vagrant-proxyconf')
57 config.proxy.http = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ""
58 config.proxy.https = ENV['https_proxy'] || ENV['HTTPS_PROXY'] || ""
59 config.proxy.no_proxy = $no_proxy
60 config.proxy.enabled = { docker: false }
65 config.vm.define node['name'] do |nodeconfig|
66 nodeconfig.vm.hostname = node['name']
67 nodeconfig.vm.network :private_network, :ip => node['ip'], :type => :static
68 nodeconfig.vm.provider 'virtualbox' do |v|
69 v.customize ["modifyvm", :id, "--memory", node['memory']]
70 v.customize ["modifyvm", :id, "--cpus", node['cpus']]
71 if node.has_key? "volumes"
72 node['volumes'].each do |volume|
73 $volume_file = "#{node['name']}-#{volume['name']}.vdi"
74 unless File.exist?($volume_file)
75 v.customize ['createmedium', 'disk', '--filename', $volume_file, '--size', volume['size']]
77 v.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', $volume_file]
81 nodeconfig.vm.provider 'libvirt' do |v|
82 v.memory = node['memory']
85 v.cpu_mode = 'host-passthrough'
86 v.management_network_address = "192.168.121.0/27"
87 nodeconfig.vm.provision 'shell' do |sh|
89 if node.has_key? "volumes"
90 $volume_mounts_dict = ''
91 node['volumes'].each do |volume|
92 $volume_mounts_dict += "#{volume['name']}=#{volume['mount']},"
93 $volume_file = "./#{node['name']}-#{volume['name']}.qcow2"
94 v.storage :file, :bus => 'sata', :device => volume['name'], :size => volume['size']
96 sh.args = ['-v', $volume_mounts_dict[0...-1]]
102 sync_type = "virtualbox"
103 if provider == :libvirt
106 config.vm.define :installer, primary: true, autostart: false do |installer|
107 installer.vm.hostname = "multicloud"
108 installer.vm.network :private_network, :ip => "10.10.10.2", :type => :static
109 installer.vm.synced_folder '../', '/root/go/src/k8-plugin-multicloud/', type: sync_type
110 installer.vm.provision 'shell' do |sh|
111 sh.path = "installer.sh"
112 sh.args = ['-p', '-v', '-w', '/root/go/src/k8-plugin-multicloud/vagrant']