-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVagrantfile
83 lines (66 loc) · 3.03 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- mode: ruby -*-
# vi: set ft=ruby :
# carrega o mesmo inventário do ansible, para termos uma fonte única
# das especificações
require 'yaml'
inventario = YAML.load_file("inventario.yml")
prebuiltbox = "tureba/postgresql-lab"
Vagrant.configure("2") do |config|
if Vagrant.has_plugin?("vagrant-vbguest")
# mais trabalho do que vale a pena
# o que as guest additions trazem, não usamos neste laboratório:
# - mouse pointer integration
# - shared folders
# - drag and drop
# - hardware-accelerated graphics
# - seamless windows
# - time synchronization
# - guest properties, control file manager and control of applications
# - memory overcommit
config.vbguest.auto_update = false
end
inventario["all"]["hosts"].each do |hostname, maquina|
config.vm.define hostname do |config|
config.vm.hostname = hostname
config.vm.box = maquina["box"] || prebuiltbox
grupo = maquina["grupo"] || File.basename(File.dirname(__FILE__))
# desabilita o diretório compartilhado, evitando requisitos extras e problemas
config.vm.synced_folder ".", "/vagrant", disabled: true
# rede host-only padrão do virtualbox: 192.168.56.0/24
config.vm.network "private_network", ip: maquina["ansible_host"], auto_config: true
config.vm.provider "virtualbox" do |virtualbox|
virtualbox.name = hostname
# agrupa as VMs deste laboratório
virtualbox.customize ["modifyvm", :id, "--groups", "/" + grupo]
virtualbox.cpus = maquina["cpus"] || 1
virtualbox.memory = maquina["memoria"] || 512
# usa tipo ideal de nic
virtualbox.default_nic_type = "virtio"
# usa controlador de video recomendado
virtualbox.customize ["modifyvm", :id, "--graphicscontroller", "vmsvga"]
virtualbox.customize ["modifyvm", :id, "--vram", "16"]
# desabilita audio
virtualbox.customize ["modifyvm", :id, "--audio", "none"]
# desabilita saida de console para log
virtualbox.customize ["modifyvm", :id, "--uart1", "off"]
virtualbox.customize ["modifyvm", :id, "--uartmode1", "disconnected"]
# desabilita dispositivos USB
virtualbox.customize ["modifyvm", :id, "--usbohci", "off"]
virtualbox.customize ["modifyvm", :id, "--usbehci", "off"]
virtualbox.customize ["modifyvm", :id, "--usbxhci", "off"]
end
config.vm.provider "libvirt" do |libvirt|
libvirt.cpus = maquina["cpus"] || 1
libvirt.memory = maquina["memoria"] || 512
end
config.vm.provision "packer", type: "ansible", run: ((config.vm.box == prebuiltbox) ? "never" : "once") do |ansible|
ansible.playbook = "vagrant/packer.yml"
ansible.host_vars = { hostname => {"ip" => maquina["ansible_host"], "grupo" => grupo} }
end
config.vm.provision "local", type: "ansible", run: "never" do |ansible|
ansible.playbook = "vagrant/vagrant.yml"
ansible.host_vars = { hostname => {"ip" => maquina["ansible_host"], "grupo" => grupo} }
end
end
end
end