Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- mode: ruby -*-
# vi: set ft=ruby :
#Variável para ficar bonitinha...
#Brincadeira, caso o seu provider nao seja o virtualbox, troque aqui!!!!
VAGRANT_VM_PROVIDER = "virtualbox"
#Versão do Vagrantfile
VAGRANTFILE_API_VERSION = "2"
#PADRAO
MEMORIA_PADRAO = 1024
CPU_PADRAO = 1
PROVISIONA_PADRAO = "echo 'Restartando a rede' && systemctl restart network && echo 'Pronto...'"
NOME_BOX_PADRAO = "centos/7"
URL_BOX_PADRAO = "centos/7"
#Definição do cluster
cluster = {
"VM1.linuxtips" => {
:ip => "192.168.56.103",
:cpus => CPU_PADRAO,
:mem => MEMORIA_PADRAO,
:provisiona => PROVISIONA_PADRAO,
:nome_box => NOME_BOX_PADRAO,
:url_box => URL_BOX_PADRAO
},
"VM2.linuxtips" => {
:ip => "192.168.56.104",
:cpus => CPU_PADRAO,
:mem => MEMORIA_PADRAO,
:provisiona => PROVISIONA_PADRAO,
:nome_box => NOME_BOX_PADRAO,
:url_box => URL_BOX_PADRAO
},
"VM3.linuxtips" => {
:ip => "192.168.56.105",
:cpus => CPU_PADRAO,
:mem => MEMORIA_PADRAO,
:provisiona => PROVISIONA_PADRAO,
:nome_box => NOME_BOX_PADRAO,
:url_box => URL_BOX_PADRAO
}
}
# Aqui é a criação das VMS...
# Possivelmente, vc nao precisará alterar muito aqui...
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vbguest.auto_update = false
cluster.each_with_index do |(hostname, info), index|
config.vm.define hostname do |cfg|
config.vm.box = info[:nome_box]
config.vm.box_url = info[:url_box]
cfg.vm.provider :virtualbox do |vb, override|
override.vm.network :private_network, ip: "#{info[:ip]}"
#config.vm.network "forwarded_port", guest: 80, host: 8081
override.vm.hostname = hostname
vb.name = hostname
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--memory", info[:mem]]
vb.customize ["modifyvm", :id, "--cpus", info[:cpus]]
vb.customize ["modifyvm", :id, "--name", hostname]
override.vm.provision :shell, :inline => info[:provisiona]
end # end provider
end # end config
end # end cluster
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment