Last active
March 8, 2017 16:03
-
-
Save mrLexx/9619121 to your computer and use it in GitHub Desktop.
PuPHPet Integration with hostsupdater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |config| | |
## Begin vagrant-hostsupdater | |
## https://github.com/cogitatio/vagrant-hostsupdater | |
## vagrant plugin install vagrant-hostsupdater | |
if Vagrant.has_plugin?("vagrant-hostsupdater") && configValues['apache']['install'] == '1' | |
config.hostsupdater.remove_on_suspend = true | |
config.hostsupdater.aliases = Array.new | |
configValues['apache']['vhosts'].each do |i, host| | |
config.hostsupdater.aliases.push(host['servername']); | |
host['serveraliases'].each do |j| | |
config.hostsupdater.aliases.push(j); | |
end | |
end | |
end | |
end |
How about add support to NGINX too?
Vagrant.configure('2') do |config|
## Begin vagrant-hostsupdater
## https://github.com/cogitatio/vagrant-hostsupdater
## vagrant plugin install vagrant-hostsupdater
if Vagrant.has_plugin?('vagrant-hostsupdater') && (configValues['apache']['install'] == '1' || configValues['nginx']['install'] == '1')
if configValues['apache']['install'] == '1'
webserver = 'apache'
server_name_key = 'servername'
server_aliases_key = 'serveraliases'
end
if configValues['nginx']['install'] == '1'
webserver = 'nginx'
server_name_key = 'server_name'
server_aliases_key = 'server_aliases'
end
config.hostsupdater.remove_on_suspend = true
config.hostsupdater.aliases = Array.new
configValues[webserver]['vhosts'].each do |i, host|
config.hostsupdater.aliases.push(host[server_name_key]);
if !host[server_aliases_key].nil?
host[server_aliases_key].each do |j|
config.hostsupdater.aliases.push(j);
end
end
end
end
eval File.read("#{dir}/puphpet/vagrant/Vagrantfile-#{data['target']}")
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice piece of code, that I just needed. One suggestion though for lines 12-14 to prevent a failure if no serveralias is set.
if !host['serveraliases'].nil?
host['serveraliases'].each do |j|
config.hostsupdater.aliases.push(j);
end
end