-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
72 lines (58 loc) · 2.56 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# This Vagrantfile contains some configuration option that you can
# tweak for your project.
# It then loads the "main" Vagrantfile from the submodule.
require 'yaml'
class CustomConfig
# Those accessors will be used by the Vagrantfile
#
# A value of 'nil' indicates that the default value can be found in
# Drifter's Vagrantfile. This is usually the case for values that
# are common for most projects.
#
# If you need to have some additional logic to define some values
# you can delete the 'attr_accessor' and provide your own method
# to return the values.
attr_accessor :box_name # url of the lxc box
attr_accessor :box_url # name of the lxc box
attr_accessor :project_name # project name (currently unused by the Vagrant file)
attr_accessor :hostname # main hostname of the box
attr_accessor :hostnames # alternative hostnames (array)
attr_accessor :box_ip # IP of the box
attr_accessor :ansible_local # use 'ansible_local' provisionner ?
attr_accessor :playbook # path to the playbook
attr_accessor :extra_vars # extra variables to pass to Ansible
attr_accessor :forwarded_ports # Port that need to be forwarded
# Retrieve the values of 'virtualization/parameters.yml' so that
# they can be used by Vagrant. If you need to change those values
# prefer editing the parameters.yml file instead.
def initialize
parameters_file = ENV.fetch('VIRTUALIZATION_PARAMETERS_FILE', 'virtualization/parameters.yml')
config = YAML::load(File.open(parameters_file))
@box_name = config['box_name'] || nil
@box_url = config['box_url'] || nil
@project_name = config['project_name'] || "example"
@hostname = config['hostname'] || "#{@project_name}.lo"
@hostnames = config['hostnames'] || nil
@box_ip = config['box_ip'] || nil
@ansible_local = true
@playbook = config['playbook'] || nil
@extra_vars = {}
@forwarded_ports = config['forwarded_ports'] || nil
end
# Getter that first check if the accessor exists on the class and if
# the value is not null before returning it.
# Otherwise fallback to the default if given or raise an error.
def get(name, default = nil)
if self.respond_to?(name) && ! self.send(name).nil?
self.send(name)
elsif default.nil?
raise "[CONFIG ERROR] '#{name}' cannot be found and no default provided."
else
default
end
end
end
Dir.chdir File.expand_path(File.dirname(__FILE__))
load 'virtualization/drifter/Vagrantfile'