-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVagrantfile
101 lines (74 loc) · 2.51 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
$ip = '10.21.6.2'
POST_UP_MSG = <<-EOM
The virtual machine should be running:
http://%{ip}
To get a shell `vagrant ssh'. On the VM, run
`sudo salt-call state.highstate' after changing salt config
See `salt/pillar/vagrant.sls' for other auto-generated passwords.
EOM
Vagrant.require_version ">= 1.6.0"
# Configuration of vagrant
def configure_vagrant
Vagrant.configure(2) do |config|
# Temporary box until there is an official debian/contrib-stretch64.
config.vm.box = "bas/contrib-stretch64"
config.vm.hostname = "vagrant-cetana.lan"
config.vm.synced_folder "salt/states", "/srv/salt", type: "virtualbox"
config.vm.synced_folder "salt/pillar", "/srv/pillar", type: "virtualbox"
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
config.vm.provision :salt do |salt|
salt.run_highstate = true
salt.verbose = true
salt.minion_config = "salt/vagrant_minion_config"
end
int = public_interface
config.vm.network :public_network, :bridge => int if int
config.vm.network :private_network, ip: $ip
config.vm.post_up_message = POST_UP_MSG % {
ip: $ip,
}
# vagrant plugin install vagrant-cachier
if Vagrant.has_plugin? "vagrant-cachier"
config.cache.scope = :box
end
end
end
# Helpers (eg. generating passwords)
require 'yaml'
require 'securerandom'
def vagrant_pillar
return YAML.load_file(vagrant_pillar_path)
end
def vagrant_pillar_path
return File.join(File.dirname(__FILE__), 'salt', 'pillar', 'vagrant.sls')
end
def ensure_pillar_is_generated
names = ['mysql_mattermost']
path = vagrant_pillar_path
return if File.exists?(path) and File.mtime(path) >= File.mtime(__FILE__)
puts 'Generating passwords ...'
if File.exists? path
pillar = YAML.load_file(path)
else
pillar = {'secrets' => {}}
end
# Generate secrets
for name in names
next if pillar['secrets'].include? name
pillar['secrets'][name] = SecureRandom.hex
end
# Some other settings
pillar['internal-ip'] = $ip
File.open(path, 'w') do |f|
f.write "# autogenerated by Vagrantfile"
YAML.dump pillar, f
end
end
def public_interface
path = File.join(File.dirname(__FILE__), '.vagrant-network-interface')
return false unless File.exists? path
return File.open(path).read.strip
end
ensure_pillar_is_generated
configure_vagrant
# vi: set ft=ruby :