-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVagrantfile
154 lines (136 loc) · 4.21 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
require 'fileutils'
require 'yaml'
# newslynx configurations
conf = YAML::load(File.open('./config.yaml'))
# machine configurations
machines = YAML::load(File.open('./machines.yaml'))
vb_conf = machines["virtualbox"]
aws_conf = machines["aws"]
# secrets configurations
secrets = YAML::load(File.open('./secrets.yaml'))
# vagrant
Vagrant.configure("2") do |config|
# box type
config.vm.box = vb_conf["box"]
config.vm.box_url = vb_conf['box_url']
# network settings
config.vm.network "forwarded_port", guest: 5000, host: 5001
config.vm.network "forwarded_port", guest: 80, host: 3001
config.vm.network "forwarded_port", guest: 5432, host: 5433
# box settings
config.vm.define "newslynx" do |machine|
# virtualbox
machine.vm.provider :virtualbox do |v|
if vb_conf["ram"]
v.memory = vb_conf["ram"]
else
v.memory = 8096
end
if vb_conf["cpu"]
v.cpus = vb_conf["cpu"]
else
v.cpus = 4
end
# include a mounted drive for postgres
if vb_conf["pg_mnt"]
d = vb_conf["pg_mnt"]
v.customize [
"createhd",
"--filename", d["path"],
"--size", d["size"]
]
v.customize [
"storageattach", :id,
"--storagectl", d["storagectl"],
"--port", d["port"],
"--device", d["device"],
"--type", d["type"],
"--medium", d["path"]
]
end
end
# aws
machine.vm.provider :aws do |aws, override|
override.vm.box = "dummy"
override.vm.synced_folder ".", "/vagrant", disabled: true
# aws.security_groups = [ 'vagrant' ]
aws.access_key_id = secrets['aws_access_key_id']
aws.secret_access_key = secrets['aws_secret_access_key']
aws.keypair_name = secrets['keypair_name']
aws.region = aws_conf['region']
aws.elastic_ip = aws_conf['elastic_ip']
aws.ami = aws_conf['ami']
aws.block_device_mapping = [
{
'DeviceName' => '/dev/xvda',
'Ebs.VolumeSize' => aws_conf['root_volume_size']
},
{
'DeviceName' => '/dev/xvdb',
'Ebs.VolumeSize' => aws_conf['db_volume_size']
}
]
aws.instance_type = aws_conf['instance_type']
aws.tags = {
'Name' => 'NewsLynx'
}
override.ssh.username = aws_conf['ssh_username']
override.ssh.private_key_path = secrets['ssh_private_key_path']
end
# provisioning
machine.vm.provision "main", type: "ansible" do |ansible|
ansible.extra_vars = { ansible_ssh_user: "vagrant", hostname: "newslynx"}
ansible.playbook = "provisioning/main.yaml"
ansible.verbose = "vvvv"
ansible.extra_vars = {
pg_mnt_path: "/dev/xvdb",
conf: conf,
secrets: secrets
}
end
# update
machine.vm.provision "update", type: "ansible" do |ansible|
ansible.extra_vars = { ansible_ssh_user: "vagrant", hostname: "newslynx"}
ansible.playbook = "provisioning/update.yaml"
ansible.verbose = "vvvv"
ansible.extra_vars = {
pg_mnt_path: "/dev/xvdb",
conf: conf,
secrets: secrets
}
end
# restart
machine.vm.provision "restart", type: "ansible" do |ansible|
ansible.extra_vars = { ansible_ssh_user: "vagrant", hostname: "newslynx"}
ansible.playbook = "provisioning/restart.yaml"
ansible.verbose = "vvvv"
ansible.extra_vars = {
pg_mnt_path: "/dev/xvdb",
conf: conf,
secrets: secrets
}
end
# stop
machine.vm.provision "stop", type: "ansible" do |ansible|
ansible.extra_vars = { ansible_ssh_user: "vagrant", hostname: "newslynx"}
ansible.playbook = "provisioning/stop.yaml"
ansible.verbose = "vvvv"
ansible.extra_vars = {
pg_mnt_path: "/dev/xvdb",
conf: conf,
secrets: secrets
}
end
# start
machine.vm.provision "start", type: "ansible" do |ansible|
ansible.extra_vars = { ansible_ssh_user: "vagrant", hostname: "newslynx"}
ansible.playbook = "provisioning/start.yaml"
ansible.verbose = "vvvv"
ansible.extra_vars = {
pg_mnt_path: "/dev/xvdb",
conf: conf,
secrets: secrets
}
end
end
end