Skip to content

DuplicateName exists: plugin cannot find current Powered On VMs using Multi-machine Loop #202

Description

@ayen-tibco

During my CI build, the .vagrant directory was accidentally delete while my VMs are still running on my ESXi, I need to rebuild the .vagrant and have vagrant up detect the current running VMs. But to no avail I can't get it running with my current multi-machine Vagrantfile. Any suggestions besides manually deleting my VMs and recreating them again?

vagrant version
Installed Version: 1.8.5
Latest Version: 1.8.5
vagrant-vsphere (1.10.0)
vSphere: 6.0U2

vagrant status
ERROR loader: Unknown config sources: ["21248980_machine_instance-1"]
ERROR loader: Unknown config sources: ["21248980_machine_instance-1"]
ERROR loader: Unknown config sources: ["21248980_machine_instance-1", "21248980_machine_instance-2"]
ERROR loader: Unknown config sources: ["21248980_machine_instance-1", "21248980_machine_instance-2"]
ERROR loader: Unknown config sources: ["21248980_machine_instance-2", "21248980_machine_instance-3"]
ERROR loader: Unknown config sources: ["21248980_machine_instance-1", "21248980_machine_instance-3"]
ERROR loader: Unknown config sources: ["21248980_machine_instance-1", "21248980_machine_instance-2"]
Current machine states:

instance-1 vagrant_vsphere.states.short_not_created (vsphere)
instance-2 vagrant_vsphere.states.short_not_created (vsphere)
instance-3 vagrant_vsphere.states.short_not_created (vsphere)

Vagrantfile:

Vagrant.require_version ">= 1.7.0"
cluster_machine_names=Array.new
unless Vagrant.has_plugin?("vsphere")
  raise 'vagrant-vsphere is not installed! Enter [vagrant plugin install vagrant-vsphere] to install.'
end

Vagrant.configure(2) do |config|
    # Disable the new default behavior introduced in Vagrant 1.7, to
    # ensure that all Vagrant machines will use the same SSH key pair.
    # See https://github.com/mitchellh/vagrant/issues/5005
    config.ssh.insert_key = false
    config.ssh.username = "vagrant"
    config.ssh.private_key_path = './example_box/vagrant_private.key'
    config.ssh.pty = true
    config.vm.box = "vsphere.box"
    config.vm.box_url = "example_box/vsphere.box"

    # Vsphere defaults
    config.vm.provider :vsphere do |vsphere|
        vsphere.host = 'somevcenterhost'
        vsphere.compute_resource_name = 'someesxihost'
        vsphere.resource_pool_name = ''
        vsphere.template_name = 'centos7'
        vsphere.user = 'vagrant@vsphere.local'
        vsphere.password = 'somepassword'
        # If you don't have SSL configured correctly, set this to 'true'
        vsphere.insecure = true
        vsphere.memory_mb = 4096
        vsphere.cpu_count = 2
    end
    N=3
    (1..N).each do |i|
        config.vm.define "instance-#{i}" do |instance|
            ins
https://guides.github.com/features/mastering-markdown/tance.vm.hostname = "instance-#{i}"
            cluster_machine_names << "instance-#{i}"
            instance.vm.network "private_network", type: "dhcp"
            # forwarded port doesn not work with vsphere plugin yet
            # instance.vm.network "forwarded_port", guest: 5556, host: host_admin_ports[N], auto_correct: true
            instance.vm.provider :vsphere do |vsphere|
                vsphere.name = "instance-#{i}"
            end

            # trick to get playbook run only once with parrallelism
            if i == N
                instance.vm.provision "ansible" do |ansible|
                    ansible.verbose = "v"
                    ansible.limit = "all"
                        # perform the entire deployment or custom tags
                        ansible.playbook = "playbooks/someplaybook.yml"
                    end
                end
           end
        end
    end
end

Debug Output:
vsphere.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions