-
Notifications
You must be signed in to change notification settings - Fork 16
/
Vagrantfile
99 lines (81 loc) · 3.37 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
require 'yaml'
require 'fileutils'
require "open3"
# load all needed vagrant helper files
Dir["#{File.dirname(__FILE__)}/vagrant/Vagrantfile.*.rb"].each {|file| require file }
# if the .config file not exists, create a default one out of the template
config_file="#{File.dirname(__FILE__)}/.lidop_config.yaml"
if(File.exist?(config_file))
else
FileUtils.cp("#{File.dirname(__FILE__)}/templates/lidop_config.yaml", config_file)
end
config_file="#{File.dirname(__FILE__)}/.vagrant_config.yaml"
if(File.exist?(config_file))
else
FileUtils.cp("#{File.dirname(__FILE__)}/templates/vagrant_config.yaml", config_file)
end
# init new settins (user and password question)
settings = Settings.new
# load the configuration out of *.config.yaml
configuration = settings.readConfig
# ask for username and password
if ARGV.include? "up" or ARGV.include? "provision"
if(File.exist?(".env"))
File.open('.env').each do |line|
puts "Set #{line.split('=')[0]} to #{line.split('=')[1]}"
ENV[line.split('=')[0].strip] = line.split('=')[1].strip
end
end
settings.init()
end
# start vagrant part
Vagrant.configure("2") do |config|
# if a extend script is defined, copy the file to remote machine
if "#{ENV['LIDOP_EXTEND']}" != ""
config.vm.provision "file", source: ENV['LIDOP_EXTEND'], destination: "/tmp/lidop/extensions/extend.yml"
end
# define default installation script
ansible_script = <<-SCRIPT
export ANSIBLE_CONFIG=/vagrant/install/ansible.cfg
export LIDOP_EXTEND=#{ENV['LIDOP_EXTEND_NEW']}
export ANSIBLE_VAULT_PASSWORD=#{settings.password}
sudo -E dos2unix /tmp/lidop/install/vault.py
sudo -E chmod +x /tmp/lidop/install/vault.py
sudo -E ansible-playbook -vv /tmp/lidop/install/install.yml --vault-password-file /tmp/lidop/install/vault.py -e 'root_password=#{settings.password}
root_user=#{settings.user_name}
SCRIPT
# define default test script
test_script = <<-SCRIPT
docker run --rm \
-v /tmp/lidop/tests/:/serverspec \
-v /var/lidop/www/tests/:/var/lidop/www/tests/ \
-e USERNAME=#{settings.user_name} \
-e PASSWORD=#{settings.password} \
-e HOST=$IPADDRESS \
-e HOSTNAME=$HOSTNAME \
-e TEST_HOST=$TEST_HOST \
registry.service.lidop.local:5000/lidop/serverspec:#{configuration["docker_image_version"]} test
SCRIPT
# no parallel start of the machines
ENV['VAGRANT_NO_PARALLEL'] = 'yes'
# read the number of workers and loop
workers = configuration["nodes"]
(0..workers).each do |worker|
# set the name of the vagrant machine
config.vm.define "lidop_#{worker}" do |machine_config|
# set the hostname
machine_config.vm.hostname = "LiDOP#{worker}"
# common scripts
if configuration["install_mode"]== "online"
machine_config.vm.provision "shell", path: "./scripts/ansible.sh"
end
# script for virtualbox
machine_config.vm.provider :virtualbox do |v, override|
Virtualbox.init(v, override, worker, settings, configuration, ansible_script, test_script)
if(worker == workers)
override.vm.provision "show_info", type: "show_info"
end
end
end
end
end