-
Notifications
You must be signed in to change notification settings - Fork 6
/
Vagrantfile
117 lines (102 loc) · 3.4 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Imports :
# Require YAML module
require 'yaml'
# variables :
VAGRANT_DIR = File.expand_path(File.dirname(__FILE__))
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">=1.8.4"
# Read YAML file with box details
servers = YAML.load_file('servers.yml')
# Create boxes
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# vagrant-cachier plugin
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :machine
end
# Iterate through entries in YAML file
servers.each do |servers|
if servers["username"]
config.ssh.username = servers["username"]
end
if servers["password"]
config.ssh.password = servers["password"]
config.ssh.insert_key = false
end
config.vm.define servers["name"] do |srv|
if servers["box_url"] != nil
srv.vm.box_url = servers["box_url"]
else
if servers["box_version"] and
srv.vm.box_version = servers["box_version"]
srv.vm.box_check_update = false
end
end
srv.vm.box = servers["box"]
if servers["ip"]
srv.vm.network "private_network", ip: servers["ip"]
end
if servers["ssh_host_port"]
# https://realguess.net/2015/10/06/overriding-the-default-forwarded-ssh-port-in-vagrant/
srv.vm.network :forwarded_port, guest: 22, host: servers['ssh_host_port'], id: "ssh"
end
# issue with symlinks ...
# srv.vm.synced_folder '.', '/vagrant', disabled: true
if Vagrant.has_plugin?("vagrant-protect")
srv.protect.enabled = servers["protected"]
end
if Vagrant.has_plugin?("vagrant-hostmanager")
srv.hostmanager.enabled = true
srv.hostmanager.manage_host = true
srv.hostmanager.manage_guest = true
srv.hostmanager.ignore_private_ip = false
srv.hostmanager.include_offline = true
srv.hostmanager.aliases = %w("#{servers["name"]}"".localdomain "#{servers["name"]}")
end
if servers["provider"] != nil
case servers["provider"]
when "virtualbox"
srv.vm.provider :virtualbox do |vb|
vb.name = "#{servers["name"]}"
vb.memory = "#{servers["ram"]}"
#vb.gui = "#{servers["gui"]}"
end
else
puts "Supported provide ATM is Virtualbox ... exiting"
end
end
if servers["ansible_provision"] != nil || ! servers["ansible_provision"]
srv.vm.provision :ansible do |ansible|
ansible.limit = servers[:name]
# control playbook name from servers.yml
if servers["playbook"] == nil
ansible.playbook = "./playbooks/default.yml"
else
ansible.playbook = "./playbooks/#{servers["playbook"]}"
end
# Pass a custom inveneoty file
if servers["inventory"] != nil
ansible.inventory_path = servers["inventory"]
end
ansible.sudo = "true"
ansible.sudo_user = "root"
ansible.host_key_checking = "false"
ansible.verbose = "-v"
# in case we have requirements for ansible role under
ansible.galaxy_roles_path = "./site-roles/"
# requirements file
# ansible.galaxy_role_file = "./requirements.yml"
# extra_vars
ansible.extra_vars = {
some_var: "some_value",
dict: {
kay1: "val1",
kay2: "val2"
}
}
end
end
end
end
end