mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
102 lines
4.2 KiB
Ruby
102 lines
4.2 KiB
Ruby
# -*- mode: ruby -*-
|
|
# vi: set ft=ruby :
|
|
|
|
# Required modules
|
|
require 'yaml'
|
|
VAGRANTFILE_API_VERSION = "2"
|
|
|
|
Vagrant.require_version ">= 1.8.7"
|
|
# Validate if all the required plugins are present
|
|
# vagrant-hostmanager replaced
|
|
required_plugins = ["vagrant-cachier", "vagrant-vbguest", "vagrant-hosts", "vagrant-azure"]
|
|
required_plugins.each do |plugin|
|
|
if not Vagrant.has_plugin?(plugin)
|
|
raise "Required vagrant plugin #{plugin} not found. Please run `vagrant plugin install #{plugin}`"
|
|
end
|
|
end
|
|
|
|
# Configuration files
|
|
CONFIGURATION_FILE = 'planetmint/pkg/configuration/vars/stack-config.yml'
|
|
HOSTS_FILE = 'planetmint/pkg/configuration/hosts/all'
|
|
HOST_VARS_PATH = 'planetmint/pkg/configuration/host_vars'
|
|
|
|
# Read configuration file(s)
|
|
instances_config = YAML.load_file(File.join(File.dirname(__FILE__), CONFIGURATION_FILE))
|
|
hosts_config = File.open(HOSTS_FILE, 'w+')
|
|
|
|
# Vars needed for VM configuration
|
|
if (instances_config["stack_type"] == "cloud" && instances_config["stack_type_provider"] == "azure")
|
|
box_name = "azure-dummy"
|
|
else
|
|
box_name = instances_config['stack_box_name']
|
|
end
|
|
|
|
# configure instance names and private ip addresses
|
|
|
|
instances_arr = Array.new
|
|
private_ipam_arr = Array.new
|
|
if instances_config['stack_type'] == "local"
|
|
for i in 1..Integer(instances_config['stack_size'])
|
|
instance_name = "bdb-node-#{i}"
|
|
instance_ip_address = "10.20.30.#{i+10}"
|
|
instances_arr.push instance_name
|
|
private_ipam_arr.push instance_ip_address
|
|
hosts_config.puts("#{instance_ip_address} ansible_user=vagrant")
|
|
File.open("#{HOST_VARS_PATH}/#{instance_ip_address}", "w+") {|f| \
|
|
f.write("ansible_ssh_private_key_file: .vagrant/machines/#{instance_name}/virtualbox/private_key") }
|
|
end
|
|
elsif
|
|
instance_name = instances_config["azure_dns_prefix"] + "." + instances_config["azure_region"] + ".cloudapp.azure.com"
|
|
instances_arr.push(instances_config["azure_dns_prefix"])
|
|
hosts_config.puts("#{instance_name} ansible_user=#{instances_config["azure_admin_username"]}")
|
|
File.open("#{HOST_VARS_PATH}/#{instance_name}", "w+") {|f| \
|
|
f.write("ansible_ssh_private_key_file: #{instances_config["ssh_private_key_path"]}") }
|
|
end
|
|
hosts_config.close
|
|
|
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
instances_arr.each_with_index do |instance, index|
|
|
config.vm.define "#{instance}" do |node|
|
|
node.vm.box = box_name
|
|
if instances_config["stack_type"] == "cloud"
|
|
node.ssh.private_key_path= instances_config["ssh_private_key_path"]
|
|
end
|
|
node.vm.box_check_update = false
|
|
# Workaround until vagrant cachier plugin supports dnf
|
|
if !(box_name.include? "fedora")
|
|
if Vagrant.has_plugin?("vagrant-cachier")
|
|
node.cache.scope = :box
|
|
end
|
|
elsif box_name == "ubuntu/xenial64"
|
|
if Vagrant.has_plugin?("vagrant-vbguest")
|
|
node.vbguest.auto_update = true
|
|
node.vbguest.auto_reboot = true
|
|
config.vbguest.no_install = true
|
|
config.vbguest.no_remote = true
|
|
end
|
|
end
|
|
node.vm.synced_folder "planetmint", "/opt/stack/planetmint"
|
|
node.vm.hostname = instance
|
|
node.vm.provision :hosts, :sync_hosts => true
|
|
node.ssh.insert_key = true
|
|
node.vm.network :private_network, ip: private_ipam_arr[index]
|
|
node.vm.provider :virtualbox do |vb, override|
|
|
vb.customize ["modifyvm", :id, "--memory", instances_config['stack_vm_memory'].to_s]
|
|
vb.customize ["modifyvm", :id, "--cpus", instances_config['stack_vm_cpus'].to_s]
|
|
end
|
|
node.vm.provider :azure do |azure, override|
|
|
azure.tenant_id = ENV['AZURE_TENANT_ID']
|
|
azure.client_id = ENV['AZURE_CLIENT_ID']
|
|
azure.client_secret = ENV['AZURE_CLIENT_SECRET']
|
|
azure.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
|
|
azure.admin_username = instances_config["azure_admin_username"]
|
|
azure.dns_name = instances_config["azure_dns_prefix"]
|
|
azure.vm_name = instances_config["azure_dns_prefix"]
|
|
azure.vm_size = instances_config["azure_vm_size"]
|
|
azure.vm_image_urn = instances_config["azure_image_urn"]
|
|
azure.resource_group_name = instances_config["azure_resource_group"]
|
|
azure.location = instances_config["azure_region"]
|
|
end
|
|
end
|
|
end
|
|
end |