Last active
March 10, 2017 14:51
-
-
Save chirauki/7b4719af45a05050b4b0e2cdcb7c7ae0 to your computer and use it in GitHub Desktop.
Abiquo demo environments with Vagrant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
VAGRANTFILE_API_VERSION = "2" | |
# Define env name | |
unless ENV['ENV_NAME'] | |
puts <<EOF | |
You have to specify an environment name using the ENV_NAME variable. | |
Eg. ENV_NAME=someenv vagrant up | |
EOF | |
exit 1 | |
end | |
# Try to parse knife.rb | |
if ENV['KNIFE'] | |
conf = File.read(ENV['KNIFE']).split("\n") | |
else | |
conf = File.read("#{ENV['HOME']}/.chef/knife.rb").split("\n") | |
end | |
chef_url_line = conf.select {|l| l.include? "chef_server_url" }.first | |
chef_url = URI.extract(chef_url_line).first | |
if ENV['VALIDATOR'] | |
validator_file = File.expand_path(ENV['VALIDATOR']) | |
else | |
conf = File.read("#{ENV['HOME']}/.chef/knife.rb").split("\n") | |
validator_line = conf.select {|l| l.include? "validation_key" }.first | |
if validator_line.nil? | |
puts <<EOF | |
The validator cert file does not exist! | |
Use the VALIDATOR env var to point to a valid file. | |
EOF | |
exit 1 | |
else | |
validator_file = "#{ENV['HOME']}/.chef/#{validator_line.split('/').last.delete('\\"')}" | |
end | |
end | |
if ENV['VALIDATOR_NAME'] | |
validator_name = ENV['VALIDATOR_NAME'] | |
else | |
conf = File.read("#{ENV['HOME']}/.chef/knife.rb").split("\n") | |
validator_name_line = conf.select {|l| l.include? "validation_client_name" }.first | |
if validator_name_line.nil? | |
puts <<EOF | |
The validator name has not been specified! | |
Use the VALIDATOR_NAME env var to set it. | |
EOF | |
exit 1 | |
else | |
validator_name = validator_line.split(' ').last.delete('\\"') | |
end | |
end | |
chef_json = { | |
'demoenv' => { | |
'environment' => ENV['ENV_NAME'] | |
}, | |
'abiquo' => { | |
'yum' => { | |
'base-repo' => 'http://mirror.abiquo.com/el$releasever/3.10/os/x86_64', | |
'updates-repo' => 'http://mirror.abiquo.com/el$releasever/3.10/updates/x86_64' | |
} | |
} | |
} | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.synced_folder ".", "/vagrant", type: "rsync" | |
config.vm.define "#{ENV['ENV_NAME']}-monolithic" do |t| | |
config.vm.hostname = "#{ENV['ENV_NAME']}-monolithic" | |
t.vm.provision "chef_client" do |chef| | |
chef.chef_server_url = chef_url | |
chef.validation_key_path = validator_file | |
chef.validation_client_name = validator_name | |
chef.node_name = "#{ENV['ENV_NAME']}-monolithic" | |
chef.add_role 'demo-monolithic' | |
chef.json = chef_json | |
chef.delete_node = true | |
chef.delete_client = true | |
end | |
end | |
config.vm.define "#{ENV['ENV_NAME']}-monitoring" do |t| | |
config.vm.hostname = "#{ENV['ENV_NAME']}-monitoring" | |
t.vm.provision "chef_client" do |chef| | |
chef.chef_server_url = chef_url | |
chef.validation_key_path = validator_file | |
chef.validation_client_name = validator_name | |
chef.add_role 'demo-monitoring' | |
chef.json = chef_json | |
chef.delete_node = true | |
chef.delete_client = true | |
end | |
end | |
config.vm.define "#{ENV['ENV_NAME']}-kvm1" do |t| | |
config.vm.hostname = "#{ENV['ENV_NAME']}-kvm1" | |
t.vm.provision "chef_client" do |chef| | |
chef.chef_server_url = chef_url | |
chef.validation_key_path = validator_file | |
chef.validation_client_name = validator_name | |
chef.add_role 'demo-kvm' | |
chef.json = chef_json | |
chef.delete_node = true | |
chef.delete_client = true | |
end | |
end | |
config.vm.define "#{ENV['ENV_NAME']}-kvm2" do |t| | |
config.vm.hostname = "#{ENV['ENV_NAME']}-kvm2" | |
t.vm.provision "chef_client" do |chef| | |
chef.chef_server_url = chef_url | |
chef.validation_key_path = validator_file | |
chef.validation_client_name = validator_name | |
chef.add_role 'demo-kvm' | |
chef.json = chef_json | |
chef.delete_node = true | |
chef.delete_client = true | |
end | |
end | |
config.vm.define "#{ENV['ENV_NAME']}-nfs" do |t| | |
config.vm.hostname = "#{ENV['ENV_NAME']}-nfs" | |
t.vm.provision "chef_client" do |chef| | |
chef.chef_server_url = chef_url | |
chef.validation_key_path = validator_file | |
chef.validation_client_name = validator_name | |
chef.add_role 'demo-nfs' | |
chef.json = chef_json | |
chef.delete_node = true | |
chef.delete_client = true | |
end | |
end | |
config.vm.provider :abiquo do |provider, override| | |
override.vm.box = 'abiquo' | |
override.vm.box_url = "https://github.com/abiquo/vagrant_abiquo/raw/master/box/abiquo.box" | |
provider.abiquo_connection_data = { | |
abiquo_api_url: 'https://chirauki40.bcn.abiquo.com/api', | |
abiquo_username: 'admin', | |
abiquo_password: 'xabiquo', | |
connection_options: { | |
ssl: { | |
verify: false | |
} | |
} | |
} | |
provider.hwprofile = '4gb' | |
provider.virtualdatacenter = 'DO fra1' | |
provider.virtualappliance = ENV['ENV_NAME'] | |
provider.template = 'CentOS 7.3.1611 x64' | |
override.ssh.private_key_path = '~/.ssh/id_rsa' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment