Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix packer vsphere-iso builder folder path #9328

Closed
sqqqrly opened this issue May 29, 2020 · 15 comments · Fixed by #9342 or #9390
Closed

Fix packer vsphere-iso builder folder path #9328

sqqqrly opened this issue May 29, 2020 · 15 comments · Fixed by #9342 or #9390

Comments

@sqqqrly
Copy link

sqqqrly commented May 29, 2020

Overview of the Issue

If one's vSphere uses a "folder of datacenters" rather than just a single data center, the vsphere-iso builder fails. This is due to an assumption that is not met for the full path in the FindFolder function (

f, err := d.finder.Folder(d.ctx, fmt.Sprintf("/%v/vm/%v", d.datacenter.Name(), name))
).

There is an older related bug report: jetbrains-infra/packer-builder-vsphere#285

Reproduction Steps

In your vSphere, hosts and clusters tab, use an extra folder:

  • vsphere
    • DataCenters <---- breaking folder: unusual, but valid in vSphere
      • cluster1
      • cluster2

Packer version

1.6.0

Simplified Packer Buildfile

Ubuntu Bionic

Hack to work around

diff --git a/builder/vsphere/driver/folder.go b/builder/vsphere/driver/folder.go
index 6349a0e04..96ad215c7 100644
--- a/builder/vsphere/driver/folder.go
+++ b/builder/vsphere/driver/folder.go
@@ -21,7 +21,7 @@ func (d *Driver) NewFolder(ref *types.ManagedObjectReference) *Folder {
 }

 func (d *Driver) FindFolder(name string) (*Folder, error) {
-       f, err := d.finder.Folder(d.ctx, fmt.Sprintf("/%v/vm/%v", d.datacenter.Name(), name))
+       f, err := d.finder.Folder(d.ctx, fmt.Sprintf("/DataCenters/%v/vm/%v", d.datacenter.Name(), name))
        if err != nil {
                return nil, err
        }
@RPitt
Copy link

RPitt commented May 29, 2020

Thanks for creating this David, does anyone have have any idea what the generalised fix might be?
I guess the code will need to discover the location of the datacenter in the vSphere path schema.

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 1, 2020

What data are you putting into the datacenter field?

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 1, 2020

I'm wondering if we can pull out the VM folder for the datacenter like this:

	folders, err := d.datacenter.Folders(d.ctx)
	if err != nil{
		return nil, err
	}
	folders.VmFolder.String()

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 1, 2020

@sqqqrly please check to see if this fixes your issue. I don't have an environment with multiple data centers.

@TmCTux
Copy link

TmCTux commented Jun 9, 2020

As this fix is now part of the nighty build it was quick to test it as I have a nested infra, and I'm still running on the same issue. Can someone else confirm? Can I be of any help for additional tests?

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 9, 2020

@TmCTux can you post the packer log from your test? it could also be useful to see what https://github.com/vmware/govmomi/blob/master/govc/USAGE.md#folderinfo shows for the vm folder on your datacenter.

@TmCTux
Copy link

TmCTux commented Jun 10, 2020 via email

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 10, 2020

I think this is indicating that the datacenter is being found. I think that I found the difference between packer and terraform. I'll push a fix to test it out.

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 10, 2020

@TmCTux
Copy link

TmCTux commented Jun 10, 2020

I've tested the fix, it looks a lot better 😃. It still fails but I believe its unrelated - my template is a work in progress, but at least it found the vm folder now! Thanks for the fast answer.

@sqqqrly
Copy link
Author

sqqqrly commented Jun 10, 2020

@jhawk28: This does not fix my problem.

╰─➤  git head
49bf9c9d37750281308a78ded64c0d1fa07da18a
╰─➤  packer -v
1.6.1
==> vsphere-iso: Creating VM...
Build 'vsphere-iso' errored: error creating vm: folder '/PSDatacenter/vm/templates' not found

The folder path should be /DataCenters/PSDatacenter/vm/templates.

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 10, 2020

@sqqqrly I don't think #9390 has been merged in yet. Can you build from the bug_8766 branch? Or use an artifact from the pull request: https://app.circleci.com/pipelines/github/hashicorp/packer/5549/workflows/c28c6870-ec5a-4f54-a180-9abd35c3133c/jobs/58799/artifacts

@sqqqrly
Copy link
Author

sqqqrly commented Jun 10, 2020

@jhawk28 OK. This works but seems a little strange.

To make it work I needed "folder": "vm/templates"

If I just use "folder": "templates", I get an error: Build 'vsphere-iso' errored: error creating vm: folder '/DataCenters/PSDatacenter/vm/templates' not found.

The path that is not found is what I expect to be the correct path. How come?

╰─➤  git head
f5a795a22e4236058214ed16d8d75cb31fcbb8d6

@jhawk28
Copy link
Contributor

jhawk28 commented Jun 10, 2020

@sqqqrly try using a folder that already exists

@ghost
Copy link

ghost commented Jul 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants