Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require explicit redirects and drop www_redirect #622

Merged
merged 5 commits into from
Jul 27, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor mapping of site_hosts in Vagrantfile
fullyint committed Jul 27, 2016
commit 7d7e104e0f072c01d036ead60efe40c80765a643
13 changes: 8 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -49,20 +49,23 @@ Vagrant.configure('2') do |config|
# Required for NFS to work
config.vm.network :private_network, ip: ip, hostsupdater: 'skip'

wordpress_sites.flat_map { |(_name, site)| site['site_hosts'] }.each do |host|
site_hosts = wordpress_sites.flat_map { |(_name, site)| site['site_hosts'] }

site_hosts.each do |host|
if !host.is_a?(Hash) or !host.has_key?('canonical')
fail_with_message File.read(File.join(ANSIBLE_PATH, 'roles/common/templates/site_hosts.j2')).sub!('{{ env }}', 'development').gsub!(/com$/, 'dev')
end
end

hostname, *aliases = wordpress_sites.flat_map { |(_name, site)| site['site_hosts'].map { |host| host['canonical'] } }
config.vm.hostname = hostname
redirects = wordpress_sites.flat_map { |(_name, site)| site['site_hosts'].select { |host| host.has_key?('redirects') }.flat_map { |host| host['redirects'] } }
main_hostname, *hostnames = site_hosts.map { |host| host['canonical'] }
config.vm.hostname = main_hostname

redirects = site_hosts.flat_map { |host| host['redirects'] }.compact

if Vagrant.has_plugin? 'vagrant-hostmanager'
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.aliases = aliases + redirects
config.hostmanager.aliases = hostnames + redirects
else
fail_with_message "vagrant-hostmanager missing, please install the plugin with this command:\nvagrant plugin install vagrant-hostmanager"
end