oscar-stack / vagrant-hosts

Manage static DNS on vagrant guests
Other
317 stars 26 forks source link

Host exports and imports do not merge properly #74

Closed Sharpie closed 6 years ago

Sharpie commented 6 years ago

The following Vagrantfile defines several instances of the same "base networking" provider:

Vagrant.configure('2') do |config|
  # Global Provider configuration.
  config.vm.provider('virtualbox') do |p, c|
    c.vm.provision('base networking', type: hosts) do |hosts|
      hosts.exports[:foo] += ['@vagrant_private_networks', ['@vagrant_hostnames']]
    end
  end
  config.vm.provider('vsphere') do |p, c|
    c.vm.provision('base networking', type: hosts) do |hosts|
      hosts.exports[:foo] += ['@facter_ipaddress', ['@vagrant_hostnames']]
    end
  end

  config.vm.define('proxy') do |vm|
    # Local VM alias
    config.vm.provider('virtualbox') do |p, c|
      c.vm.provision('base networking', type: hosts) do |hosts|
        hosts.exports[:foo] += ['@vagrant_private_networks', ['some-alias']]
      end
    end
  end
end

These should all merge together for the proxy VM to create an array of exports containing records for both the hostnames and some-alias. However, the merge method for the hosts provisioner configuration only merges the hosts attribute:

https://github.com/oscar-stack/vagrant-hosts/blob/2.8.1/lib/vagrant-hosts/config.rb#L86-L93

Config Builder also has a variation on this issue: it just overwrites the exports attribute each time a new block appears instead of merging values together in a configure_exports method like:

https://github.com/oscar-stack/vagrant-hosts/blob/2.8.1/lib/vagrant-hosts/config_builder/1_x.rb#L23-L28