Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Build 'vsphere-iso' errored: error creating vm: folder '/datacenter/vm/' not found #285

Open
Klashblack opened this issue Nov 5, 2019 · 19 comments

Comments

@Klashblack
Copy link

I am at a loss here. I have this working in my Lab but soon as i try in our Production environment i am running into this issue. The only thing that is different is our datacenter is nested in a folder.

I get the following error
vsphere-iso output will be in this color.

==> vsphere-iso: Creating VM...
Build 'vsphere-iso' errored: error creating vm: folder '/DATACENTER/vm/' not found

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: error creating vm: folder '/DATACENTER/vm/' not found

==> Builds finished but no artifacts were created.
{

"builders": [
    {
        "type": "vsphere-iso",
        "vcenter_server": "vcenterserver,
        "username": "{{user `vsphere_username`}}",
        "password": "{{user `vsphere_password`}}",
        "datacenter": "datacenter",
        "cluster": "CLUSTER1",
        "communicator": "winrm",
        "winrm_username": "Administrator",
        "winrm_password": "{{user `admin_password`}}",
        "vm_name": "W2K19STDX64TEST",
        "convert_to_template": "true",
        "datastore": "datastore",
        "cpus": "2",
        "ram": "4096",
        "network_card": "vmxnet3",
        "disk_controller_type": "lsilogic-sas",
        "CPU_hot_plug": true,
        "RAM_hot_plug": true,
        "disk_size": "51200",
        "iso_paths": [
            "[datastore] ISO - Windows Server/SW_DVD9_Win_Server_STD_CORE_2019_1809.1_64Bit_English_DC_STD_MLF_X22-02970.ISO",
            "[datastore] ISO - Windows Server/VMware-tools-windows-10.3.10-12406962.iso"
        ],
        "floppy_files": [
            "setup/autounattend.xml",
            "setup/setup.ps1",
            "setup/vmtools.cmd"
        ]
    }
],
"provisioners": [
    {
        "type": "windows-update"
    }
]

}

@lbonilla68
Copy link

Try adding this line to your config "vm_folder": "Templates/Packer"

This assumes you have a folder called "Packer" in another folder called "Templates" right under your datacenter object called "datacenter".

@Klashblack
Copy link
Author

there is not a configuration key called "vm_folder" but there is one called "folder" And when i use this
"folder": Template
(which there is a folder called Template)
I just end up getting this error
vsphere-iso: error creating vm: folder '/datacenter/vm/Template' not found

@Klashblack
Copy link
Author

I'm also wondering if this is a problem since the datacenter in our non production is nested in a folder like so, FOLDER/datacenter

@roderick-mackintosh
Copy link

Seems related to the version of vsphere
I have the same issue if using with vSphere Version 6.0.0
It works fine with vSphere version 6.7

@Klashblack
Copy link
Author

Interesting we are on vSphere Client version 6.7.0.40000

@seanfeeney
Copy link

As far as I can tell the vpshere_folder variable (config key) is used for where the template is stored when it's exported. Not where it is actually on the datastore. I've been banging my head against the same wall for a few days.

So under the "vms and templates" view in vsphere (ctrl + alt + 2) if you create a folder (Template) that key should now work.

Hope that helps.

@roderick-mackintosh
Copy link

Upon further investigation, it may not be vSphere version related. My vSphere 6.0 environment has the datacenter nested in a folder (as per @Klashblack case). My vSphere 6.7 environment doesnt.

@Klashblack
Copy link
Author

Our vsphere is on 6.7 as well. Hoping someone has a idea to get this working. Would really love to implement this in our environment to create monthly templates

@lbonilla68
Copy link

Do you use folders in the vcenter hierarchy? In this screen shot the values for the packer config are as such

"datacenter": "Home",
"cluster": "CORP-VSI-01",

image

However for where I want the templates to be created I have to fully specify the path to the folder like so

"folder": "Templates/Packer-Builds",

image

Hope this helps

@whyiseverythingmadesocomplicated

I am also experiencing this, vcenter 6 & 6.5.

@Klashblack
Copy link
Author

Klashblack commented Jan 8, 2020

We use folders but the problem is that the DataCenter is in a Folder. So that is the issue it seems. I talked to the VMware team and they won't remove the Datacenter out of a folder.. So in your case it would be
VCENTER->
FOLDER ->
DATACENTER ->
CLUSTERS ->
Since the Datacenter is in a folder that is where the issue is and not sure how to fix it

@whyiseverythingmadesocomplicated

I have numerous vcenter setups I can play with so just tried this. In the VM view of vcenter6.5
folder/datacenter/vmfolder FAIL
datacenter/vmfolder SUCCESS (well I pass this step and then get into similar issues for resourcepool)

@whyiseverythingmadesocomplicated

I sorted the resourcepool issue by putting host as foldername/foldername2/hostname. Similar for folder doesn't work.

@Klashblack
Copy link
Author

Were you able to get it to work with FOLDER/DATACENTER/HOST ? my Vmware team won't move our datacenter out of a folder. They like to seperate them by EAST and WEST folders

@austness
Copy link

austness commented Feb 21, 2020

We have experienced this problem as well due to our datacenters being under a folder. There is a solution to this! This works on our environment (packer 1.5.4 vCenter 6.7u2). Our structure looks like this:

vCenter
|--Folder
|----Datacenter(s)
|------Cluster(s)

When running packer build file.json it would spit out the error:
vsphere-iso: error creating vm: folder '/DATACENTER/vm/FOLDER’ not found.

To fix this we had to recompile packer after making modifications. This may sound scary but its actually not that bad.

Steps to resolve:
1 Download the git repo for packer: https://github.com/hashicorp/packer
2 Download/install Go: https://golang.org/dl/
3 On windows you will need to download and install: http://www.mingw.org/
You can also find the compile portion of this piece here: https://github.com/hashicorp/packer/blob/master/.github/CONTRIBUTING.md#setting-up-go-to-work-on-packer Scroll down to: ‘Setting up Packer for Dev’
4 Navigate to the problem file: packer/builder/vsphere/driver/folder.go
5 Edit the file folder.go and at line 24 you should see this:
f, err := d.finder.Folder(d.ctx, fmt.Sprintf("/%v/vm/%v", d.datacenter.Name(), name))
The first ‘/%v’ is your datacenter and the second ‘%/v’ would be any other folders below your datacenter you want to place your vm
6 Add the name of your folder before the first ‘/%v’. It should look something like this:
"YOUR_FOLDER/%v/vm/%v"
7 Save the file and navigate to the root of the packer repo
8 Run this command ‘go build -o bin/packer’ if you are on windows make sure you add ‘.exe’ to
the end. This will create the ‘new’ packer and place it in a folder in the packer root: packer/bin/packer
9 Once the build is complete place it into your system path and try running it again with your same code. (You shouldn’t need to specify ‘folder’ unless its below the datacenter level.

Hopefully this is helpful!

Problem:
The problem is inside the actual Go code used with packer, portion it uses on where to build the VM is coded like so: “/%v/vm/%v” Essentially the ‘vm’ is where the vm is actually created so in the case you place it under a datacenter it would be DATACENTER/vm but if you have a folder above your datacenter it will come out as /DATACENTER/vm/FOLDER.

@Klashblack
Copy link
Author

Thanks @austness !! Much appreciated. Yeah we ended up finding this solution as well. My next step is maybe if there is a way we can create it as a Variable? But i'm a novice in GO. I really appreciate your help! Looks like this is what we will have to do for now though. At least it is working!

sqqqrly added a commit to ohlemacher/packer that referenced this issue May 12, 2020
When one's vsphere data center(s) are contained within a data center
folder, vsphere-iso is broken.   There is no way to specificy a "folder"
in the packer template to allow builds to complete.  See
jetbrains-infra/packer-builder-vsphere#285 for
more details.

This change and removal of the folder template key, allows successful
builds.

DCO 1.1 Signed-off-by: David Ohlemacher <dohlemacher@infinidat.com>
sqqqrly added a commit to ohlemacher/packer that referenced this issue May 12, 2020
When one's vsphere data center(s) are contained within a data center
folder, vsphere-iso is broken.   There is no way to specificy a "folder"
in the packer template to allow builds to complete.  See
jetbrains-infra/packer-builder-vsphere#285 for
more details.

This change and removal of the folder template key, or using a folder
value that includes "vm/..." allows successful builds.  It is not clear
why vm/ must be in this key and is also in the code.

DCO 1.1 Signed-off-by: David Ohlemacher <dohlemacher@infinidat.com>
@sqqqrly
Copy link

sqqqrly commented May 29, 2020

If anyone hits this bug, it was also reported here: hashicorp/packer#9328

@freola
Copy link

freola commented Jun 8, 2021

Hi!

We are on packer version 1.7.2 and still get this issue, I did see that the bug that @sqqqrly post for this is closed but it seams not been fixed or mayby this is something else?, anyone else that still has this problem?

vsphere-iso: output will be in this color.

==> vsphere-iso: Creating VM...
Build 'vsphere-iso' errored after 144 milliseconds 234 microseconds: error creating vm: folder '/Datacenter/vm' not found

==> Wait completed after 144 milliseconds 234 microseconds

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: error creating vm: folder '/Datacenter/vm' not found

==> Builds finished but no artifacts were created.

@patneville
Copy link

Absolutely still an issue that does not store the image. Between this and the Waiting for IP issue this provisioner is maddening right now for a first time user.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

9 participants