forked from pigeontech/cptserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
126 lines (113 loc) · 4.89 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
####################################
### Load Configuration Variables
####################################
require 'yaml'
$vconfig = YAML::load_file("config/config.yaml")
# Handle directory
def getDirectory(directory, tabs)
if tabs == 2
tabs = "\t"
else
tabs = ""
end
rewrite = "\n\t"+tabs+"<Directory "+directory+">\n"
$vconfig['directory'].each_with_index do |val, key|
rewrite = rewrite + "\t\t"+ tabs + val + "\n"
end
rewrite = rewrite+"\t"+tabs+"</Directory>\n"
return rewrite
end
# Handle vhosts
vhosts = ""
$vconfig['vhosts'].each_with_index do |v, k|
vhosts = vhosts + "<VirtualHost *:80>\n" + getDirectory(v['DocumentRoot'],1) + "\n"
v.each_with_index do |val, key|
vhosts = vhosts + "\t" + val.join(' ') + "\n"
end
vhosts = vhosts + "\n</VirtualHost>\n\n"
end
# Handle vhostsssl
vhostsssl = "<IfModule mod_ssl.c>\n\n"
$vconfig['vhosts'].each_with_index do |v, k|
vhostsssl = vhostsssl + "\t<VirtualHost *:443>\n" + getDirectory(v['DocumentRoot'],2) + "\n"
v.each_with_index do |val, key|
vhostsssl = vhostsssl + "\t\t" + val.join(' ') + "\n"
end
vhostsssl = vhostsssl + "\n\t\tErrorLog ${APACHE_LOG_DIR}/error.log\n\t\tCustomLog ${APACHE_LOG_DIR}/access.log combined\n\n\t\tSSLEngine on\n\n\t\tSSLCertificateFile /etc/apache2/ssl/apache.crt\n\t\tSSLCertificateKeyFile /etc/apache2/ssl/apache.key\n\n\t\t<FilesMatch \"\.(cgi|shtml|phtml|php)$\">\n\t\t\tSSLOptions +StdEnvVars\n\t\t</FilesMatch>\n\n\t\t<Directory /usr/lib/cgi-bin>\n\t\t\tSSLOptions +StdEnvVars\n\t\t</Directory>\n\n\t</VirtualHost>\n\n"
end
vhostsssl = vhostsssl + "</IfModule>\n"
# Openssl args
opensslargs = ""
$vconfig['ssl'].each do |k, v|
opensslargs = opensslargs+v+'\n'
end
####################################
### Running Vagrant
####################################
Vagrant.configure("2") do |config|
config.vagrant.host = :detect
config.ssh.shell = $vconfig['vagrant']['ssh_shell']
config.ssh.username = $vconfig['vagrant']['ssh_username']
config.ssh.keep_alive = true
####################################
### Machine Setup
####################################
config.vm.box = $vconfig['vagrant']['box']
config.vm.box_url = $vconfig['vagrant']['box_url']
config.vm.network "private_network", ip: $vconfig['vagrant']['box_ip']
config.vm.hostname = $vconfig['vagrant']['vm_hostname']
config.vm.network "forwarded_port", guest: 80, host: $vconfig['vagrant']['box_port']
config.vm.network "forwarded_port", guest: 3306, host: $vconfig['mysql']['port']
config.vm.network "forwarded_port", guest: 443, host: $vconfig['vagrant']['box_port_ssl']
config.vm.synced_folder $vconfig['vagrant']['vm_webroot'], $vconfig['vagrant']['vm_docroot'], :owner => "vagrant", :group => "www-data", :mount_options => ["dmode=777","fmode=777"]
####################################
### VirtualBox Provider
####################################
config.vm.provider "virtualbox" do |virtualbox|
virtualbox.customize ["modifyvm", :id, "--cpuexecutioncap", $vconfig['vagrant']['vm_cpu']]
virtualbox.customize ["modifyvm", :id, "--name", $vconfig['vagrant']['vm_name']]
virtualbox.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
virtualbox.customize ["modifyvm", :id, "--memory", $vconfig['vagrant']['vm_memory']]
virtualbox.customize ["modifyvm", :id, "--rtcuseutc", "on"]
virtualbox.customize ["setextradata", :id, "--VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
####################################
### Shell Provisioning
####################################
config.vm.provision "shell" do |s|
s.path = "config/shell/default.sh"
end
####################################
### Puppet Provisioning
####################################
config.vm.provision "puppet" do |puppet|
puppet.facter = {
"ssh_username" => $vconfig['vagrant']['ssh_username'],
"fqdn" => $vconfig['vagrant']['vm_hostname'],
"syspackages" => $vconfig['syspackages'].join(','),
"phpmodules" => $vconfig['phpmodules'].join(','),
"apachemodules" => $vconfig['apachemodules'].join(','),
"vhostsphp" => $vconfig['vhosts'].join(','),
"vhosts" => vhosts,
"vhostsssl" => vhostsssl,
"opensslargs" => opensslargs,
"xdebug" => $vconfig['xdebug'].join("\n")+"\n",
"errors" => $vconfig['errors'].join("\n")+"\n",
"password" => $vconfig['mysql']['password'],
}
puppet.options = "--verbose"
puppet.manifests_path = "config/puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.module_path = "config/puppet/modules"
end
####################################
### Run SQL
####################################
config.vm.provision "shell",
inline: "mysql -uroot -p"+$vconfig['mysql']['password']+" < '/etc/mysql/remote.sql'"
####################################
### Ready
####################################
config.vm.provision "shell",
inline: "cat /vagrant/config/shell/ready.txt"
end