Hi.
If the virtual machine disk path or file name have a space, packer fails to create the virtual disk.
type: vmware-iso
remote_type: esx5
https://github.com/hashicorp/packer/blob/master/builder/vmware/iso/driver_esx5.go
: Creating required virtual machine disks
: Error creating disk: 'vmkfstools -c 40960M -d zeroedthick -a lsilogic /vmfs/volumes/MyVolume/Path with spaces/file name with spaces.vmdk'
: Stderr: Extra arguments at the end of the command line.
: Step "stepCreateDisk" failed, aborting...
Packer v1.2.5
Host: Windows 10 64-bit
Thank you.
hey @icnocop, have you tried with the latest version of packer ?
Hi @azr. Yes, it also fails with packer 1.3.1.
Sample packer.json
Have you tried escaping the spaces?
Ah nevermind, I see. We derive this path.
I've pushed a patch that should fix this -- can you test it out? Here's a windows build of Packer with the patch applied:
Thank you, @SwampDragons.
I just tried this out.
I'm still getting an error message, but it's a little different.
2018/10/10 13:54:27 ui: ==> packer test: Creating required virtual machine disks
2018/10/10 13:54:27 packer.exe: 2018/10/10 13:54:27 [INFO] Creating disk with Path: packer test\disk.vmdk and Size: 1024M
2018/10/10 13:54:27 packer.exe: 2018/10/10 13:54:27 [DEBUG] Opening new ssh session
2018/10/10 13:54:27 packer.exe: 2018/10/10 13:54:27 [DEBUG] starting remote command: vmkfstools -c 1024M -d zeroedthick -a lsilogic /vmfs/volumes/MyVolume/packer\ test/disk.vmdk
2018/10/10 13:54:27 packer.exe: 2018/10/10 13:54:27 [ERROR] Remote command exited with '255': vmkfstools -c 1024M -d zeroedthick -a lsilogic /vmfs/volumes/MyVolume/packer\ test/disk.vmdk
2018/10/10 13:54:27 ui error: ==> packer test: Error creating disk: 'vmkfstools -c 1024M -d zeroedthick -a lsilogic /vmfs/volumes/MyVolume/packer\ test/disk.vmdk'
==> packer test: Stderr: Failed to create virtual disk: The system cannot find the file specified (25).
2018/10/10 13:54:27 ui error: ==> packer test: Error creating disk: 'vmkfstools -c 1024M -d zeroedthick -a lsilogic /vmfs/volumes/MyVolume/packer\ test/disk.vmdk'
==> packer test: Stderr: Failed to create virtual disk: The system cannot find the file specified (25).
2018/10/10 13:54:27 ui error: ==> packer test: Step "stepCreateDisk" failed, aborting...
It created the directory /vmfs/volumes/MyVolume/packer
but I expected it to create /vmfs/volumes/MyVolume/packer test
.
If the /vmfs/volumes/MyVolume/packer test
directory already exists, then it gets further.
How strange. Maybe quoting it instead of escaping the spaces is better. Can you try this one?
packer.zip
Sorry that one doesn't work either.
I found this (older) reference which indicates single quotes should be used instead of double quotes:
https://www.vmware.com/support/developer/vcli/vcli41/doc/reference/vmkfstools.html
2018/10/10 16:21:51 ui: ==> packer test: Creating required virtual machine disks
2018/10/10 16:21:51 packer.exe: 2018/10/10 16:21:51 [INFO] Creating disk with Path: packer test\disk.vmdk and Size: 1024M
2018/10/10 16:21:51 packer.exe: 2018/10/10 16:21:51 [DEBUG] Opening new ssh session
2018/10/10 16:21:51 packer.exe: 2018/10/10 16:21:51 [DEBUG] starting remote command: vmkfstools -c 1024M -d zeroedthick -a lsilogic "/vmfs/volumes/MyVolume/packer test/disk.vmdk"
2018/10/10 16:21:51 packer.exe: 2018/10/10 16:21:51 [ERROR] Remote command exited with '255': vmkfstools -c 1024M -d zeroedthick -a lsilogic "/vmfs/volumes/MyVolume/packer test/disk.vmdk"
2018/10/10 16:21:51 ui error: ==> packer test: Error creating disk: 'vmkfstools -c 1024M -d zeroedthick -a lsilogic "/vmfs/volumes/MyVolume/packer test/disk.vmdk"'
==> packer test: Stderr: Failed to create virtual disk: The system cannot find the file specified (25).
2018/10/10 16:21:51 ui error: ==> packer test: Error creating disk: 'vmkfstools -c 1024M -d zeroedthick -a lsilogic "/vmfs/volumes/MyVolume/packer test/disk.vmdk"'
==> packer test: Stderr: Failed to create virtual disk: The system cannot find the file specified (25).
2018/10/10 16:21:51 ui error: ==> packer test: Step "stepCreateDisk" failed, aborting...
Thank you.
Okay, so same failure as when the spaces are escaped. Did it still create a directory named "/vmfs/volumes/MyVolume/packer"?
I wonder if there's a command earlier that's creating that directory which we also need to escape. e.g., the actual disk being created has been created somewhere with the wrong name. Can you share the full logs? I'm hoping we can find where this is happening.
Here's a windows build with the disk name single-quoted:
packer.zip
Right, packer.zip from 2018-10-10T22:23:22Z
created the directory /vmfs/volumes/MyVolume/packer
.
The last packer.zip you sent me also created the directory /vmfs/volumes/MyVolume/packer
and failed with the same error.
I manually ran vmkfstools
and it turns out escaping the space with a backslash, using double quotes, or using single quotes will create the virtual disk if the directory already exists.
You are right and packer tries to create the directory before creating the virtual disk.
I would expect that if packer fails to create the directory that it would exit at that point and not continue to try and create the virtual disk.
Here's the full log with the last packer.zip.
packer.log
Here's a snippet:
2018/10/11 14:01:26 packer.exe: 2018/10/11 14:01:26 [DEBUG] starting remote command: test -e /vmfs/volumes/MyVolume/packer test
2018/10/11 14:01:26 packer.exe: 2018/10/11 14:01:26 [ERROR] Remote command exited with '2': test -e /vmfs/volumes/MyVolume/packer test
2018/10/11 14:01:26 packer.exe: 2018/10/11 14:01:26 [DEBUG] starting remote command: mkdir -p /vmfs/volumes/MyVolume/packer test
2018/10/11 14:01:26 ui: ==> packer test: Creating required virtual machine disks
2018/10/11 14:01:26 packer.exe: 2018/10/11 14:01:26 [INFO] Creating disk with Path: packer test\disk.vmdk and Size: 1024M
2018/10/11 14:01:26 packer.exe: 2018/10/11 14:01:26 [DEBUG] Opening new ssh session
2018/10/11 14:01:26 packer.exe: 2018/10/11 14:01:26 [DEBUG] starting remote command: vmkfstools -c 1024M -d zeroedthick -a lsilogic '/vmfs/volumes/MyVolume/packer test/disk.vmdk'
2018/10/11 14:01:26 packer.exe: 2018/10/11 14:01:26 [ERROR] Remote command exited with '255': vmkfstools -c 1024M -d zeroedthick -a lsilogic '/vmfs/volumes/MyVolume/packer test/disk.vmdk'
2018/10/11 14:01:26 ui error: ==> packer test: Error creating disk: 'vmkfstools -c 1024M -d zeroedthick -a lsilogic '/vmfs/volumes/MyVolume/packer test/disk.vmdk''
==> packer test: Stderr: Failed to create virtual disk: The system cannot find the file specified (25).
2018/10/11 14:01:26 ui error: ==> packer test: Error creating disk: 'vmkfstools -c 1024M -d zeroedthick -a lsilogic '/vmfs/volumes/MyVolume/packer test/disk.vmdk''
==> packer test: Stderr: Failed to create virtual disk: The system cannot find the file specified (25).
2018/10/11 14:01:26 ui error: ==> packer test: Step "stepCreateDisk" failed, aborting...
Thank you!
Awesome, those logs were super helpful. I found the code that was creating the directory and it was being called by the driver's d.sh() command, which doesn't appear to provide any quoting for inputs. I went through the driver code and quoted all calls to d.sh() that contain pathing; hopefully this one works.
Thank you.
It got further this time! :smile:
Snippet:
2018/10/11 17:40:18 ui: ==> packer test: Registering remote VM...
2018/10/11 17:40:18 packer.exe: 2018/10/11 17:40:18 [DEBUG] Opening new ssh session
2018/10/11 17:40:18 packer.exe: 2018/10/11 17:40:18 [DEBUG] Starting remote scp process: scp -vt /vmfs/volumes/MyVolume/packer test
2018/10/11 17:40:18 packer.exe: 2018/10/11 17:40:18 [DEBUG] Started SCP session, beginning transfers...
2018/10/11 17:40:18 packer.exe: 2018/10/11 17:40:18 [DEBUG] Copying input data into temporary file so we can read the length
2018/10/11 17:40:18 packer.exe: 2018/10/11 17:40:18 [DEBUG] scp: Uploading packer test.vmx: perms=C0644 size=2851
2018/10/11 17:40:18 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/11 17:40:18 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/11 17:40:18 ui error: ==> packer test: Step "StepRegister" failed, aborting...
2018/10/11 17:40:18 ui error: Build 'packer test' errored: unexpected EOF
Okay, yep, found a different unquoted call. Try this one:
packer.zip
We're close!
The new packer.exe failed in the same step.
I noticed that the vmx file wasn't uploaded, but it was created locally as expected, at %temp%\packer-vmx334163899\packer test.vmx
.
I expected if the vmx file failed to get uploaded, packer would not try to register it.
Thank you.
I've quoted the upload path.
The upload happens as part of the registration step, so the fact that the error message says StepRegister is expected. It is failing as soon as the upload fails.
Thank you for the explanation. ๐
It seems the file path is getting split and cut off somewhere...
Snippet:
2018/10/12 15:38:20 packer.exe: 2018/10/12 15:38:20 [DEBUG] Starting remote scp process: scp -vt "/vmfs/volumes/MyVolume/packer test
2018/10/12 15:38:20 packer.exe: 2018/10/12 15:38:20 [DEBUG] scp: Uploading packer test.vmx": perms=C0644 size=2851
2018/10/12 15:38:20 ui error: ==> packer test: Error registering VM: Process exited with status 2
2018/10/12 15:38:20 ui error: ==> packer test: Step "StepRegister" failed, aborting...
googling, it looks like scp's ambiguous target error only works when you escape spaces with backslashes, not with quoting. Let's hope that's true.
Thanks for being such a trooper with this testing.
Thanks for trying to fix the issue. ๐
The vmx still wasn't uploaded.
2018/10/12 19:05:43 ui: ==> packer test: Registering remote VM...
2018/10/12 19:05:43 packer.exe: 2018/10/12 19:05:43 [DEBUG] Opening new ssh session
2018/10/12 19:05:43 packer.exe: 2018/10/12 19:05:43 [DEBUG] Starting remote scp process: scp -vt /vmfs/volumes/MyVolume/packer/ test/packer
...
2018/10/12 19:05:44 packer.exe: 2018/10/12 19:05:44 [DEBUG] scp: Uploading test.vmx: perms=C0644 size=2851
2018/10/12 19:05:44 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/12 19:05:44 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/12 19:05:44 ui error: ==> packer test: Step "StepRegister" failed, aborting...
Okay, let's try single quoting everything, which I probably should have done first:
packer.zip
The vmx was not uploaded.
Snippet:
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 Writing VMX to: C:\Users\RAMI~1.ABU\AppData\Local\Temp\packer-vmx274719135\packer test.vmx
2018/10/15 14:54:20 ui: ==> packer test: Registering remote VM...
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 '"/vmfs/volumes/MyVolume/packer test/packer test.vmx"'
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] Opening new ssh session
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] Starting remote scp process: scp -vt '"/vmfs/volumes/MyVolume/packer test
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] Started SCP session, beginning transfers...
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] Copying input data into temporary file so we can read the length
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] scp: Uploading packer test.vmx"': perms=C0644 size=2851
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] SCP session complete, closing stdin pipe.
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] Waiting for SSH session to complete.
2018/10/15 14:54:20 packer.exe: 2018/10/15 14:54:20 [DEBUG] non-zero exit status: 2
2018/10/15 14:54:20 ui error: ==> packer test: Error registering VM: Process exited with status 2
2018/10/15 14:54:20 ui error: ==> packer test: Step "StepRegister" failed, aborting...
Ah. The scp process is being smart and helpful and splitting the file for me into the target dir and the file basename. Which makes the quoting break. So this needs to be done from within the scp process, not the provisioner. This is so weird. Does this mean that scp breaks for _all_ situations where files have a space in their name? I'm going to do some local testing and get back to you.
The good (?) news is I can't reproduce with the file provisioner. I'm going to take a look at how it handles things.
okay, I _think_ I actually was barking up the wrong tree with my changes to the filename that was being passed to scp. I've reverted my hamhanded attempts at escaping and added a bunch of loglines so we can see exactly where this is failing -- I think it was actually failing on the register call right after the upload, until I tried to escape it and then broke the upload.
The vmx was not uploaded.
Snippet:
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 Writing VMX to: C:\Users\RAMI~1.ABU\AppData\Local\Temp\packer-vmx102050579\packer test.vmx
2018/10/16 14:32:22 ui: ==> packer test: Registering remote VM...
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 DEBUGGING 6794 (1): upload path is: /vmfs/volumes/MyVolume/packer test/packer test.vmx
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 DEBUGGING 6794 (7): target dir is \vmfs\volumes\MyVolume\packer test
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 DEBUGGING 6794 (8): target file is packer test.vmx
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 [DEBUG] Opening new ssh session
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 [DEBUG] Starting remote scp process: scp -vt /vmfs/volumes/MyVolume/packer test
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 [DEBUG] Started SCP session, beginning transfers...
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 [DEBUG] Copying input data into temporary file so we can read the length
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 [DEBUG] scp: Uploading packer test.vmx: perms=C0644 size=2851
2018/10/16 14:32:22 packer.exe: 2018/10/16 14:32:22 DEBUGGING 6794 (2): upload errored: scp: ambiguous target
2018/10/16 14:32:22 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/16 14:32:22 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/16 14:32:22 ui error: ==> packer test: Step "StepRegister" failed, aborting...
I found this blog post that indicates escaping the space with a backslash should resolve the issue:
http://mikestechblog.com/ubuntu-antenna/scp-ambiguous-target-error-solved/
"[If] running inside a shell script ... you would add two backslashes"
Yeah, that's what I tried in this failure
Those look like forwardslashes to me, not blackslashes. ๐
Yes, yes they do; I think they got mangled somewhere in the scp processing. I found somewhere online that suggested trying triple slashes instead to force the scp interpreter to process it correctly. We can try that. Incoming.
This one contains the escaping: vmxPath = strings.Replace(vmxPath,
,
\\ , -1)
packer.zip
and this one contains vmxPath = strings.Replace(vmxPath,
,
\ , -1)
I think the previous one I did was vmxPath = strings.Replace(vmxPath,
, "\\ ", -1)
which would have only added a single backslash because it wasn't a raw string; I thought that'd be enough, but the backslash is being turned into a forward slash and misinterpreted a directory in that situation. Let's see if the extra escaping makes any difference.
Snippet:
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 Writing VMX to: C:\Users\RAMI~1.ABU\AppData\Local\Temp\packer-vmx073477835\packer test.vmx
2018/10/16 17:08:16 ui: ==> packer test: Registering remote VM...
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 DEBUGGING 6794 (1): upload path is: /vmfs/volumes/MyVolume/packer\\\ test/packer\\\ test.vmx
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 DEBUGGING 6794 (7): target dir is \vmfs\volumes\MyVolume\packer\ test\packer
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 DEBUGGING 6794 (8): target file is test.vmx
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 [DEBUG] Opening new ssh session
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 [DEBUG] Starting remote scp process: scp -vt /vmfs/volumes/MyVolume/packer/ test/packer
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 [DEBUG] Started SCP session, beginning transfers...
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 [DEBUG] Copying input data into temporary file so we can read the length
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 [DEBUG] scp: Uploading test.vmx: perms=C0644 size=2851
2018/10/16 17:08:16 packer.exe: 2018/10/16 17:08:16 DEBUGGING 6794 (2): upload errored: scp: ambiguous target
2018/10/16 17:08:16 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/16 17:08:16 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/16 17:08:16 ui error: ==> packer test: Step "StepRegister" failed, aborting...
Snippet:
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 Writing VMX to: C:\Users\RAMI~1.ABU\AppData\Local\Temp\packer-vmx239176391\packer test.vmx
2018/10/16 17:12:23 ui: ==> packer test: Registering remote VM...
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 DEBUGGING 6794 (1): upload path is: /vmfs/volumes/MyVolume/packer\\ test/packer\\ test.vmx
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 DEBUGGING 6794 (7): target dir is \vmfs\volumes\MyVolume\packer\ test\packer
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 DEBUGGING 6794 (8): target file is test.vmx
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 [DEBUG] Opening new ssh session
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 [DEBUG] Starting remote scp process: scp -vt /vmfs/volumes/MyVolume/packer/ test/packer
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 [DEBUG] Started SCP session, beginning transfers...
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 [DEBUG] Copying input data into temporary file so we can read the length
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 [DEBUG] scp: Uploading test.vmx: perms=C0644 size=2851
2018/10/16 17:12:23 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/16 17:12:23 packer.exe: 2018/10/16 17:12:23 DEBUGGING 6794 (2): upload errored: scp: ambiguous target
2018/10/16 17:12:23 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/16 17:12:23 ui error: ==> packer test: Step "StepRegister" failed, aborting...
So same problem either way -- the escaped space is getting translated into a slash and a space. It thinks there's a slash saying there's a directory and not a slash saying to escape the space.
I think this is a problem with our shell communicator and windows hosts, and isn't specific to esxi, which should make it easier for me to reproduce. In the morning I'll dig out a windows vm and see if I can repro without the esxi element.
Okay, I've managed to reproduce and (I think) fix only 3 days after I promised to start on this.
It _is_ a problem with the ssh communicator and has nothing to do with esxi in particular. In fact, it has nothing to do with _Windows_ in particular. I got hung up on it happening only on Windows, because when I tried to repro from my OSX machine, it didn't happen. But then I launched my Windows vm and the same test case that worked on OSX worked just fine on Windows too. It turns out that's because it doesn't happen for just any old space in the file path; only spaces that exist in the _directory_ the file is to be uploaded to. Doesn't matter if there are spaces in the base name; "packer test.vmx" is just fine. But if it's in the dir, then stuff hits the fan. "/path/to/my file/packer.vmx" is where the excitement happens.
The fact that this happens on all platforms instead of just one is _awesome_ because it means that this is a one-line fix without any special casing (okay, two lines counting the explanatory comment). Give this one a whirl for me and lemme know if it works for you. It solved my toy test case, but I obviously don't trust that it'll work in the wild until you give me the ๐
oh, actually wait two minutes -- That build won't work because I still need to apply all of the other esxi-specific fixes we found earlier.
Okay. Try this one:
packer.zip
vmx was not uploaded.
Snippet:
2018/10/19 13:50:10 packer.exe: 2018/10/19 13:50:10 Writing VMX to: C:\Users\RAMI~1.ABU\AppData\Local\Temp\packer-vmx247926339\packer test.vmx
2018/10/19 13:50:10 ui: ==> packer test: Registering remote VM...
2018/10/19 13:50:10 packer.exe: 2018/10/19 13:50:10 [DEBUG] Opening new ssh session
2018/10/19 13:50:10 packer.exe: 2018/10/19 13:50:10 [DEBUG] Starting remote scp process: scp -vt /vmfs/volumes/MyVolume/packer/ test
2018/10/19 13:50:10 packer.exe: 2018/10/19 13:50:10 [DEBUG] Started SCP session, beginning transfers...
2018/10/19 13:50:10 packer.exe: 2018/10/19 13:50:10 [DEBUG] Copying input data into temporary file so we can read the length
2018/10/19 13:50:10 packer.exe: 2018/10/19 13:50:10 [DEBUG] scp: Uploading packer test.vmx: perms=C0644 size=2851
2018/10/19 13:50:10 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/19 13:50:10 ui error: ==> packer test: Error registering VM: scp: ambiguous target
2018/10/19 13:50:10 ui error: ==> packer test: Step "StepRegister" failed, aborting...
2018/10/19 13:50:10 ui error: Build 'packer test' errored: unexpected EOF
Oy. When I was cleaning the test-build up, I moved the SINGLE IMPORTANT LINE OF CODE up too far and broke everything.
I really hope this one fixes it. Sorry.
Thank you, @SwampDragons .
It's worked! :)
๐ ๐ฏ ๐ ๐พ
Omg phew. Thanks so much for bearing with me while I careened in circles on this one. I wish I'd figured out that I could repro locally sooner.
I'll try to get this into the v1.3.2 release; if anything else comes up please let me know.
Thanks again for finding and fixing the issues! ๐
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.