Closed zimbeo closed 6 months ago
Hi @zimbeo thanks for opening up this issue and for providing the debug logs. I see that you are using a bundled version of the vSphere plugin with a JSON template. Before diving further into this issue could you try running this build with a new version of the plugin.
You can install the plugin by running packer plugins install github.com/hashicorp/vsphere
.
By running this command you will install the latest version of the plugin, which is newer than the version currently bundled with Packer. After installing the plugin you can run Packer like you would normally and it will automatically use the installed plugin.
Please let me know if you run into this issue with the latest plugin version.
Hello, sorry for the delay in response here - haven't had time to loop back to this.
I just tested once more and got the same result with the latest plugin version as well.
[zimbeo@server1 Template.2019.GUI]$ packer plugins install github.com/hashicorp/vsphere
[zimbeo@server1 Template.2019.GUI]$ packer plugins installed
/home/zimbeo/.config/packer/plugins/github.com/hashicorp/vsphere/packer-plugin-vsphere_v1.2.3_x5.0_linux_amd64
[zimbeo@server1 Template.2019.GUI]$ packer build -force -var-file ../setup/shared/2019/variables.json ./winserver2019.json
vsphere-iso: output will be in this color.
==> vsphere-iso: Creating VM...
vsphere-iso: Closing sessions ....
Build 'vsphere-iso' errored after 290 milliseconds 75 microseconds: error creating vm: The name 'Template.2019.GUI' already exists.
==> Wait completed after 290 milliseconds 118 microseconds
==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: error creating vm: The name 'Template.2019.GUI' already exists.
==> Builds finished but no artifacts were created.
I'll look into it in the new year in personal time.
I'm not seeing this with my test today:
CONFIRM: Build a VMware Photon OS 5 Template for VMware vSphere?
Continue? (y/n)
y
Building a VMware Photon OS 5 Template for VMware vSphere...
Initializing HashiCorp Packer and required plugins...
Starting the build....
packer build -force -on-error=ask
vsphere-iso.linux-photon: output will be in this color.
==> vsphere-iso.linux-photon: Creating CD disk...
vsphere-iso.linux-photon: Creating hybrid image...
vsphere-iso.linux-photon: Done copying paths from CD_dirs
==> vsphere-iso.linux-photon: Uploading packer3573943403.iso to packer_cache/packer3573943403.iso
==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-develop already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Templates/linux-photon-5.0-develop is a template, attempting to convert it to a vm
==> vsphere-iso.linux-photon: Creating VM...
==> vsphere-iso.linux-photon: Customizing hardware...
Specificaly...
==> vsphere-iso.linux-photon: the vm/template Templates/linux-photon-5.0-develop already exists, but deleting it due to -force flag
==> vsphere-iso.linux-photon: Templates/linux-photon-5.0-develop is a template, attempting to convert it to a vm
Same result if a template or a vm.
I was able to reproduce this with some additional testing:
The cause is that you have the following set:
{
...
"folder": "vm/Templates",
...
}
For a base path, you only need to provide:
{
...
"folder": "Templates",
...
}
If you want to nest, you can use:
{
...
"folder": "foo/bar",
...
}
Community Note
When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.
Overview of the Issue
I have a builder that works great if the template I'm trying to create doesn't already exist. Before I added the
folder
key into my builder it would work properly when supplying the-force
flag, it would delete the template and recreate it. Now that I've added thefolder
key and value to my builder, if I attempt to execute the build again (with the-force
flag) then it errors out with the messageThe name 'Template.2022.Core' already exists.
This happens regardless of supplying the
-force
flag or not. It seems like Packer doesn't understand to force delete the image if thefolder
key is supplied. Whenever I remove thefolder
key from the builder it deletes the existing template and builds a new one.Reproduction Steps
Run packer build with the
-force
flag with the folder specified in the builder file. Have a template/VM already created in that folder with the same name of the template to be created.packer build -force -var-file ./variables.json ./winserver2022.json
Packer version
1.9.4
Simplified Packer Template
Template https://gist.github.com/zimbeo/da249e3d1f89c1a1f99661eb5ec4abc9
Example Variables file https://gist.github.com/zimbeo/827d0ac73c07e273844dacf63934a25d
Operating system and Environment details
Red Hat Enterprise Linux release 8.8 vSphere 7.0.3
Log Fragments and crash.log files
https://gist.github.com/zimbeo/873a8381b9f37295bff6cb94ae9d8c58