-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
171 lines (153 loc) · 6.1 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.9.1"
require 'getoptlong'
#http://stackoverflow.com/questions/14124234/how-to-pass-parameter-on-vagrant-up-and-have-it-in-the-scope-of-chef-cookbook
opts = GetoptLong.new(
[ '--help', GetoptLong::NO_ARGUMENT ],
[ '--vmname', GetoptLong::REQUIRED_ARGUMENT ],
[ '--cpus', GetoptLong::REQUIRED_ARGUMENT ],
[ '--memory', GetoptLong::REQUIRED_ARGUMENT ],
[ '--nfs', GetoptLong::NO_ARGUMENT ],
[ '--forward-port', GetoptLong::REQUIRED_ARGUMENT ],
[ '--private-ip', GetoptLong::REQUIRED_ARGUMENT ],
[ '--ansible-playbook', GetoptLong::REQUIRED_ARGUMENT ],
[ '--extra-vars-file', GetoptLong::REQUIRED_ARGUMENT ]
)
cpus = 2
memory = 4096
vmname = (0...8).map { (65 + rand(26)).chr }.join
nfs = false
private_ip = "192.168.234.234"
extra_vars_file = "ansible/extra-vars/eclipse_cpp.yml"
ansible_playbook = "ansible/site.yml"
forward_ports = []
begin
opts.each do |opt, arg|
case opt
when '--help'
puts <<-EOF
There are some additional arguments available specifically for this Vagrantfile for deployment.
--help:
show help
--cpus: (default: #{cpus})
number fo cpus for the virtual machine
--memory: (default: #{memory})
memory of the virtual machine in [MB]
--vmname: (default: randomly assigned)
the name of the virtualmachine for the virtual machine provider (e.g. VirtualBox)
--nfs: (default: #{nfs})
mount through nfs
--private-ip: (default: #{private_ip})
ip for the private network
--forward-port:
forward port from guest to host in the form "guest:host"
--ansible-playbook: (default: #{ansible_playbook})
the file containing the ansible deployment playbook
--extra-vars-file: (default: #{extra_vars_file})
ansible vars in a vars-file (either json or yaml) for provisiong the environment
use a relative path in this tree
http://docs.ansible.com/ansible/playbooks_variables.html#passing-variables-on-the-command-line
EOF
when '--cpus'
cpus = arg.to_i
when '--memory'
memory = arg.to_i
when '--nfs'
nfs = true
when '--private-ip'
private_ip = arg
when '--forward-port'
forward_ports << arg
when '--vmname'
vmname = arg
when '--ansible-playbook'
ansible_playbook = arg
when '--extra-vars-file'
extra_vars_file = arg
end # case
end # each
rescue GetoptLong::InvalidOption => invalid_option
puts "there are options that are not handled by that Vagrantfile, but might be handled upstream by vagrant"
puts "if they cannot be handled by vagrant, they will cause termination"
end
# prepend extra_vars_
extra_vars_file = File.basename( Dir.pwd ) + "/" + extra_vars_file
ansible_playbook = File.basename( Dir.pwd ) + "/" + ansible_playbook
Vagrant.configure("2") do |config|
# Configure the box to use
config.vm.box = 'bento/ubuntu-16.04'
# config.vm.box = 'bento/centos-7.1'
if Vagrant.has_plugin?("vagrant-cachier")
# Configure cached packages to be shared between instances of the same base box.
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
config.cache.scope = :box
config.cache.enable :apt
config.cache.enable :apt_lists
config.cache.enable :composer
config.cache.enable :gem
# config.cache.enable :pip
config.cache.enable :generic, {
"ivy2" => { cache_dir: "/home/vagrant/.ivy2" },
"sbt" => { cache_dir: "/home/vagrant/.sbt" },
"ansible_download" => { cache_dir: "/tmp/ansible_download" },
}
# OPTIONAL: If you are using VirtualBox, you might want to use that to enable
# NFS for shared folders. This is also very useful for vagrant-libvirt if you
# want bi-directional sync
config.cache.synced_folder_opts = {
type: nfs ? :nfs : nil,
# # The nolock option can be useful for an NFSv3 client that wants to avoid the
# # NLM sideband protocol. Without this option, apt-get might hang if it tries
# # to lock files needed for /var/cache/* operations. All of this can be avoided
# # by using NFSv4 everywhere. Please note that the tcp option is not the default.
# mount_options: ['rw', 'vers=3', 'tcp', 'nolock']
}
# For more information please check http://docs.vagrantup.com/v2/synced-folders/basic_usage.html
end
if Vagrant.has_plugin?("vagrant-vbguest")
# set auto_update to false, if you do NOT want to check the correct
# additions version when booting this machine
config.vbguest.auto_update = true
# do NOT download the iso file from a webserver
config.vbguest.no_remote = false
config.vbguest.installer_arguments = ['--nox11']
end
# Configure the network interfaces
config.vm.network :private_network, ip: private_ip
forward_ports.each do |forward|
guest,host = forward.split ":"
config.vm.network :forwarded_port, guest: guest, host: host
end
# Configure shared folders
if nfs
config.vm.synced_folder "." , "/vagrant", id: "vagrant-root", :nfs => true, :mount_options => ['nfsvers=3', 'vers=3', 'actimeo=1', 'rsize=8192', 'wsize=8192', 'timeo=14', :nolock, :udp, :intr, :auto, :exec, :rw]
config.vm.synced_folder ".." , "/project", id: "project-root", :nfs => true, :mount_options => ['nfsvers=3', 'vers=3', 'actimeo=1', 'rsize=8192', 'wsize=8192', 'timeo=14', :nolock, :udp, :intr, :auto, :exec, :rw]
else
config.vm.synced_folder "." , "/vagrant", id: "vagrant-root"
config.vm.synced_folder ".." , "/project", id: "project-root"
end
# configure the ssh connection
config.ssh.forward_agent = true
config.ssh.forward_x11 = true
# Configure VirtualBox environment
config.vm.provider :virtualbox do |v|
v.name = vmname
v.customize [ "modifyvm", :id, "--memory", memory ]
v.customize [ "modifyvm", :id, "--cpus", cpus ]
end
# Provision the box
# config.vm.provision :ansible do |ansible|
# ansible.playbook = "ansible/site.yml"
# end
# Provision the box bootstrapping
config.vm.provision "shell" do |s|
s.path = "bootstrap.sh"
# s.args = [extra_vars_file]
end
config.vm.provision "shell" do |s|
s.path = "ansible.sh"
s.args = [ansible_playbook,extra_vars_file]
s.privileged = false
end
end