-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVagrantfile
More file actions
147 lines (131 loc) · 5.11 KB
/
Copy pathVagrantfile
File metadata and controls
147 lines (131 loc) · 5.11 KB
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
$vagrant_box = "ubuntu/jammy64"
## InfluxDB
$influxdb_username = "admin"
$influxdb_password = "Passw0rd!"
$influxdb_token = "Object1stDemoT0ken!"
$influxdb_org = "ObjectFirst"
$influxdb_bucket = "ObjectFirstBucket"
## Grafana
$grafana_password = "Passw0rd!"
## Scripts
$build_prerequisites = <<SCRIPT
echo "...Updating OS..."
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y jq
SCRIPT
$install_influxdb = <<SCRIPT
echo "...Installing InfluxDB..."
sudo rm -f /etc/apt/sources.list.d/influxdata.list
curl --silent --location -O \
https://repos.influxdata.com/influxdata-archive.key
echo "943666881a1b8d9b849b74caebf02d3465d6beb716510d86a39f6c8e8dac7515 influxdata-archive.key" \
| sha256sum --check - && cat influxdata-archive.key \
| gpg --dearmor \
| tee /etc/apt/trusted.gpg.d/influxdata-archive.gpg > /dev/null \
&& echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main' \
| tee /etc/apt/sources.list.d/influxdata.list
sudo apt-get update && sudo apt-get install -y influxdb2
sudo systemctl enable --now influxdb.service
SCRIPT
$create_influx_database = <<SCRIPT
echo "...Create Influx database..."
timeout 10 bash -c "until </dev/tcp/localhost/8086; do sleep 1; done"
influx setup \
--username #{$influxdb_username} \
--password #{$influxdb_password} \
--token #{$influxdb_token} \
--org #{$influxdb_org} \
--bucket #{$influxdb_bucket} \
--force
SCRIPT
$install_grafana = <<SCRIPT
echo "...Installing Grafana..."
sudo rm -f /etc/apt/sources.list.d/grafana.list
sudo apt-get install -y apt-transport-https software-properties-common wget
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update && sudo apt-get install -y grafana
sudo systemctl enable --now grafana-server
SCRIPT
$reset_grafana_admin_password = <<SCRIPT
echo "...Reset Grafana admin password..."
timeout 10 bash -c "until </dev/tcp/localhost/3000; do sleep 1; done"
sudo /usr/share/grafana/bin/grafana cli --homepath "/usr/share/grafana" admin reset-admin-password admin
curl -uadmin:admin -X PUT -H "Content-Type: application/json" -d '{
"oldPassword": "admin",
"newPassword": "#{$grafana_password}",
"confirmNew": "#{$grafana_password}"
}' http://localhost:3000/api/user/password
SCRIPT
$create_grafana_data_source = <<SCRIPT
echo "...Create Grafana data source..."
timeout 10 bash -c "until </dev/tcp/localhost/3000; do sleep 1; done"
curl -uadmin:#{$grafana_password} -X POST -H "Content-Type: application/json" -d '{
"name":"#{$influxdb_bucket}",
"type":"influxdb",
"url":"http://localhost:8086",
"access":"proxy",
"basicAuth":true,
"isDefault":true,
"jsonData": {
"dbName":"#{$influxdb_bucket}",
"defaultBucket": "#{$influxdb_bucket}",
"httpMode": "POST",
"organization": "#{$influxdb_org}",
"version": "Flux"
},
"secureJsonData": {
"token": "#{$influxdb_token}"
}
}' http://localhost:3000/api/datasources
curl -uadmin:#{$grafana_password} -X POST -H "Content-Type: application/json" -d '{
"name":"VeeamBR",
"type":"influxdb",
"url":"http://localhost:8086",
"access":"proxy",
"basicAuth":true,
"isDefault":false,
"jsonData": {
"dbName":"VeeamBR",
"defaultBucket": "VeeamBR",
"httpMode": "POST",
"organization": "#{$influxdb_org}",
"version": "Flux"
},
"secureJsonData": {
"token": "#{$influxdb_token}"
}
}' http://localhost:3000/api/datasources
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = $vagrant_box
config.vm.provider :virtualbox do |v, override|
v.customize ["modifyvm", :id, "--memory", "4096"]
v.customize ["modifyvm", :id, "--cpus", "2"]
v.customize ["modifyvm", :id, "--vram", 32]
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--audio", "none"]
v.customize ["modifyvm", :id, "--name", "ObjectFirst Grafana demo - Ubuntu 22.04"]
v.customize ["modifyvm", :id, "--usb", "off"]
v.linked_clone = true if Vagrant::VERSION >= '1.8.0'
end
config.vm.network "forwarded_port", :guest => 8083, :host => 8083
config.vm.network "forwarded_port", :guest => 8086, :host => 8086
config.vm.network "forwarded_port", :guest => 8090, :host => 8090
config.vm.network "forwarded_port", :guest => 8099, :host => 8099
config.vm.network "forwarded_port", :guest => 3000, :host => 3000
config.vm.network "forwarded_port", :guest => 8888, :host => 8888
config.vm.synced_folder "objectfirst", "/objectfirst"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provision "shell", inline: <<-SHELL
#{$build_prerequisites}
#{$install_influxdb}
#{$create_influx_database}
#{$install_grafana}
#{$reset_grafana_admin_password}
#{$create_grafana_data_source}
SHELL
end