diff --git a/box/Vagrantfile b/box/Vagrantfile index 19db24e..0e4e50f 100644 --- a/box/Vagrantfile +++ b/box/Vagrantfile @@ -27,6 +27,10 @@ vconfig = load_config([ "#{host_config_dir}/local.config.yml" ]) +# Override all drupalvm.test values according to project root: +require (File.expand_path('drutopiavm', host_config_dir)) +set_overrides_per_project(vconfig) + provisioner = vconfig['force_ansible_local'] ? :ansible_local : vagrant_provisioner if provisioner == :ansible playbook = "#{host_drupalvm_dir}/provisioning/playbook.yml" @@ -42,15 +46,12 @@ Vagrant.require_version ">= #{vconfig['drupalvm_vagrant_version_min']}" ensure_plugins(vconfig['vagrant_plugins']) -# Acquire a hostname from the project root -vm_hostname = File.basename(ENV['DRUPALVM_PROJECT_ROOT']).gsub("_", "-") - Vagrant.configure('2') do |config| # Set the name of the VM. See: http://stackoverflow.com/a/17864388/100134 - config.vm.define "#{vm_hostname}.local" #vconfig['vagrant_machine_name'] + config.vm.define vconfig['vagrant_machine_name'] # Networking configuration - config.vm.hostname = "#{vm_hostname}-coop-vm" #vconfig['vagrant_hostname'] + config.vm.hostname = vconfig['vagrant_hostname'] config.vm.network :private_network, ip: vconfig['vagrant_ip'], auto_network: vconfig['vagrant_ip'] == '0.0.0.0' && Vagrant.has_plugin?('vagrant-auto_network') diff --git a/provisioning/box/drutopiavm.rb b/provisioning/box/drutopiavm.rb new file mode 100644 index 0000000..d9423d3 --- /dev/null +++ b/provisioning/box/drutopiavm.rb @@ -0,0 +1,15 @@ +def set_overrides_per_project(config) + # Acquire a hostname from the project root + project_dir_name = File.basename(ENV['DRUPALVM_PROJECT_ROOT']).gsub("_", "-") + host_name = "#{project_dir_name}.test" + + # Override all vconfig values with the new names + config['vagrant_hostname'] = host_name + config['vagrant_machine_name'] = "#{project_dir_name}-vm" + config['drupal_domain'] = host_name + config['hostname_fqdn'] = + config['apache_vhosts'].each do |host| + host['servername'].sub!('drupalvm.test', host_name) + host['serveralias'].gsub!('drupalvm.test', host_name) if host['serveralias'] + end +end diff --git a/provisioning/box/pre-tasks/00-name_by_path.yml b/provisioning/box/pre-tasks/00-name_by_path.yml index d44b13a..b1b8cb1 100644 --- a/provisioning/box/pre-tasks/00-name_by_path.yml +++ b/provisioning/box/pre-tasks/00-name_by_path.yml @@ -15,5 +15,5 @@ # See also provisioning/box/config - name: set vagrant hostname according to the project folder set_fact: - vagrant_hostname: "{{ proj_root_safe }}.local" - vagrant_machine_name: "{{ proj_root_safe }}-coop-vm" + vagrant_hostname: "{{ proj_root_safe }}.test" + vagrant_machine_name: "{{ proj_root_safe }}-vm"