-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
76 lines (64 loc) · 2.45 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
# -*- mode: ruby -*-
# vi: set ft=ruby sw=2 :
#
#################################################################
# title: Vagrantfile #
# desciption: Bootstrap development environment with Vagrant #
# and Virtualbox. All configuration is done through #
# ./vagrant.yml file in the same folder. Please DO #
# NOT EDIT Vagrantfile unless you really-really #
# need to do so. Instead edit ./vagrant.yml and #
# all the changes will be fetched by Vagrant on #
# next provision or up. #
# developer: ddnomad #
# version: 0.1.2 #
#################################################################
require 'yaml' # to parse config file
# get a username
USER = `who | cut -f1 -d ' '`.strip.freeze
# load configuration file and sub-sections
VCONF = YAML.load_file('./vagrant.yml').freeze
VB_PROPS = VCONF['vb_props'].freeze
ANS_PROPS = VCONF['ansible_props'].freeze
# generic properties
BASE_BOX = VCONF['base_box'].freeze
VC_VERSION = VCONF['vc_version'].freeze
# virtualbox properties
VB_NAME = VB_PROPS['name'].freeze
VB_CPUS = VB_PROPS['cpus'].freeze
VB_CAP = VB_PROPS['cpu_cap'].freeze
VB_RAM = VB_PROPS['ram'].freeze
# ansible properties
ANS_BP = ANS_PROPS['base_path'].freeze
ANS_CM = ANS_PROPS['comp_mode'].freeze
ANS_PB = ANS_PROPS['playbook'].freeze
ANS_CFG = ANS_PROPS['config'].freeze
ANS_REQ = ANS_PROPS['requirements_path'].freeze
# on-call commands to execute
ON_CALL_CMDS = VCONF['exec_on_call'].freeze
# ports to forward
FORW_PORTS = VCONF['forward_ports'].freeze
# actual Vagrant configuration block
Vagrant.configure(VC_VERSION) do |config|
# specifying base box
config.vm.box = BASE_BOX
# configuring Virtualbox provider
config.vm.provider :virtualbox do |vb|
vb.name = VB_NAME
vb.cpus = VB_CPUS
vb.memory = VB_RAM
vb.customize ['modifyvm', :id, '--cpuexecutioncap', VB_CAP]
end
# provision the guest with Ansible
config.vm.provision 'ansible_local' do |ansible|
ansible.compatibility_mode = ANS_CM
ansible.provisioning_path = ANS_BP
ansible.playbook = ANS_PB
ansible.config_file = ANS_CFG
ansible.extra_vars = { user: USER }
end
# forwarding ports
FORW_PORTS.each do |guest_port, host_port|
config.vm.network 'forwarded_port', guest: guest_port, host: host_port
end
end