A Simple repository for using, building, & maintaining my vagrantfile customizations (e.g. ruby code)
Since the index of add-on logic is small I am placing the code snippets below.
unless Vagrant.has_plugin?("vagrant-docker-compose")
system("vagrant plugin install vagrant-docker-compose")
puts "Dependencies installed, please try the command again."
exit
end
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.windows?
end
def OS.linux?
OS.unix? and not OS.mac?
end
end
if OS.windows?
puts "Vagrant launched from windows."
else
puts "Vagrant launched from mac."
unless Vagrant.has_plugin?("vagrant-gatling-rsync")
system("vagrant plugin install vagrant-gatling-rsync")
puts "Rsync Dependency installed, please try the command again."
end
end
require 'yaml'
nodes = YAML.load_file("./yaml/vagrant.yaml")
This is very helpful when you want to mount/share content
unless node['folders'].nil?
node['folders'].each do |folder|
node_config.vm.synced_folder folder['local'], folder['virtual']
end
end
unless node["initScript"].nil?
node["initScript"].each do |script|
node_config.vm.provision :shell, path: script["init"], privileged: true
end
node_config.vm.provider :openstack do |os|
os.keypair_name = openstack['key']
os.username = openstack['username']
os.password = openstack['password']
os.tenant_name = openstack['tenant']
os.flavor = node['flavor']
os.image = node["box"]
os.security_groups = openstack['security_groups'] # SecGroups must be setup prior to usage
os.openstack_auth_url = "http://" + openstack['auth_url'] + ":5000/v2.0/tokens" # e.g. "#{ENV['OS_AUTH_URL']}/tokens"
os.networks = openstack["tenant_network"]
if defined? nodes["floatingip_pool"]
os.floating_ip_pool = nodes["floatingip_pool"]
else
os.floating_ip = node["floating_ip"]
end
end
if node["box"] == 'centos-7' then
node_config.ssh.username = "centos"
elsif node["box"] == 'trusty64'
node_config.ssh.username = "ubuntu"
else
node_config.ssh.username = "root"
end
node["forwards"].each do |port|
node_config.vm.network "forwarded_port", guest: port["guest"], host: port["host"], id: port["id"]
end