Created
December 24, 2014 04:18
-
-
Save momchilov/a5ac8f10590c4f5b8ec0 to your computer and use it in GitHub Desktop.
Modification of the vagrantfile to automatically deploy instances fast
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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
require 'ipaddr' | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# Box configuration | |
config.vm.box = "ubuntu/trusty64" | |
# Puppet Agent configuration - setting master server | |
#config.vm.provision "puppet_server" do |puppet| | |
# puppet.puppet_server = "puppet.example.com" | |
# puppet.options = "--verbose --debug" | |
#end | |
node_groups = [ | |
# Node group definitions | |
# A ':machine' number is added to each machine's ':name' | |
{ | |
:name => "node", # hostname for the machines | |
:machines => 2, # number of machines to be created | |
:ssh_port_start => 2000, # a start port to forward ssh to the host machine | |
:ip_network => "10.0.2.0/24" # network range for the group | |
}, | |
] | |
# DO NOT MODIFY BELOW | |
node_groups.each do |node_group| | |
ip_range = IPAddr.new(node_group[:ip_network]).to_range.to_a[2..-1] # available ip address range, | |
# excluding the first and last usable | |
node_group[:machines].times do |machine_number| | |
machine_number+=1 # so it starts from 1, instead of 0 | |
node_name = "#{node_group[:name]}#{machine_number}" | |
config.vm.define "#{node_name}" do |node| | |
node.vm.hostname=node_name | |
# disabling default port forwarding for ssh | |
node.vm.network :forwarded_port, guest: 22, host: 2200, id: "ssh", disabled: "true" | |
# assigning new port to forward for ssh | |
node.vm.network :forwarded_port, guest: 22, host: node_group[:ssh_port_start] + machine_number | |
node.vm.network "private_network", ip: ip_range.shift.to_s # return ip from pool and delete it from array | |
node.vm.provision :hosts do |hosts| | |
hosts.autoconfigure = true | |
#hosts.add_host "10.0.2.2", ["puppet"] | |
end | |
node.vm.provider "virtualbox" do |v| | |
v.name = node_name | |
v.memory = 256 # allocate RAM in MB | |
v.cpus = 2 # number of CPU cores to use | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment