Skip to content

Instantly share code, notes, and snippets.

@mrLexx
Last active March 8, 2017 16:03
Show Gist options
  • Save mrLexx/9619121 to your computer and use it in GitHub Desktop.
Save mrLexx/9619121 to your computer and use it in GitHub Desktop.
PuPHPet Integration with hostsupdater
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
@tpinne
Copy link

tpinne commented Jul 8, 2014

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

@ricardofontanelli
Copy link

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