diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index e8abe106c..794db57b2 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -145,18 +145,16 @@ module VagrantPlugins new_provs = [] other_provs = other.provisioners.dup @provisioners.each do |p| - if p.name - other_p = other_provs.find { |o| p.name == o.name } - if other_p - # There is an override. Take it. - other_p.config = p.config.merge(other_p.config) - other_p.run ||= p.run - next if !other_p.preserve_order + other_p = other_provs.find { |o| p.id == o.id } + if other_p + # There is an override. Take it. + other_p.config = p.config.merge(other_p.config) + other_p.run ||= p.run + next if !other_p.preserve_order - # We're preserving order, delete from other - p = other_p - other_provs.delete(other_p) - end + # We're preserving order, delete from other + p = other_p + other_provs.delete(other_p) end # There is an override, merge it into the diff --git a/plugins/kernel_v2/config/vm_provisioner.rb b/plugins/kernel_v2/config/vm_provisioner.rb index aedafe9fe..59833c850 100644 --- a/plugins/kernel_v2/config/vm_provisioner.rb +++ b/plugins/kernel_v2/config/vm_provisioner.rb @@ -9,6 +9,15 @@ module VagrantPlugins # @return [String] attr_reader :name + # Internal unique name for this provisioner + # Set to the given :name if exists, otherwise + # it's set as a UUID. + # + # Note: This is for internal use only. + # + # @return [String] + attr_reader :id + # The type of the provisioner that should be registered # as a plugin. # @@ -35,6 +44,7 @@ module VagrantPlugins @logger = Log4r::Logger.new("vagrant::config::vm::provisioner") @logger.debug("Provisioner defined: #{name}") + @id = name || SecureRandom.uuid @config = nil @invalid = false @name = name diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index 17d121ed7..ef3734898 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -424,6 +424,24 @@ describe VagrantPlugins::Kernel_V2::VMConfig do expect{ subject.finalize! }.to_not raise_error end + it "generates a uuid if no name was provided" do + allow(SecureRandom).to receive(:uuid).and_return("MY_CUSTOM_VALUE") + + subject.provision("shell", path: "foo") { |s| s.inline = "foo" } + subject.finalize! + + r = subject.provisioners + expect(r[0].id).to eq("MY_CUSTOM_VALUE") + end + + it "sets id as name if a name was provided" do + subject.provision("ghost", type: "shell", path: "motoko") { |s| s.inline = "motoko" } + subject.finalize! + + r = subject.provisioners + expect(r[0].id).to eq(:ghost) + end + describe "merging" do it "ignores non-overriding runs" do subject.provision("shell", inline: "foo", run: "once") @@ -439,6 +457,16 @@ describe VagrantPlugins::Kernel_V2::VMConfig do expect(merged_provs[1].run).to eq("always") end + it "does not merge duplicate provisioners" do + subject.provision("shell", inline: "foo") + subject.provision("shell", inline: "bar") + + merged = subject.merge(subject) + merged_provs = merged.provisioners + + expect(merged_provs.length).to eql(2) + end + it "copies the configs" do subject.provision("shell", inline: "foo") subject_provs = subject.provisioners