Packer 0.7.5
VMware ESXi 5.5.0
Windows Vista Enterprise 64-bit guest
packer.json:
{
"variables": {
"name": null
},
"builders": [
{
"name": "{{user `name`}}",
"vm_name": "{{user `name`}}",
"disk_size": 40960,
"floppy_files": [
"./winVistax64-enterprise/Autounattend.xml"
],
"type": "vmware-iso",
"remote_type": "esx5",
"remote_host": "192.168.0.x",
"remote_username": "root",
"remote_password": "password",
"remote_datastore": "datastore1",
"remote_cache_datastore": "datastore1",
"remote_cache_directory": "ISOs",
"headless": true,
"format": "ovf",
"guest_os_type": "winvista-64",
"iso_url": "en_windows_vista_enterprise_x64_dvd_vl_x13-17316.iso",
"iso_checksum_type": "sha1",
"iso_checksum": "3b55166cb5c6aa61d4d53190c271bed0bf0aa961",
"ssh_username": "Administrator",
"ssh_password": "password",
"ssh_wait_timeout": "30m",
"output_directory": "{{user `name`}}",
"tools_upload_flavor": "windows",
"shutdown_command": "reg export HKLM\\System\\MountedDevices MountedDevices.reg",
"shutdown_timeout": "15m",
"vmx_data": {
"RemoteDisplay.vnc.enabled": "true",
"RemoteDisplay.vnc.port": "5900",
"gui.fitguestusingnativedisplayresolution": "FALSE",
"memsize": "4096",
"numvcpus": "1",
"virtualHW.version": "8",
"scsi0.virtualDev": "lsisas1068",
"ethernet0.connectiontype": "bridged",
"ethernet0.networkName": "Network Name"
}
}
],
"provisioners": [
{
"type": "shell",
"remote_path": "/tmp/script.bat",
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
"scripts": [
"scripts/vmtool.bat"
]
},
{
"type": "shell",
"inline": [
"shutdown /r /t 5 /f /d p:4:1 /c \"Packer Reboot\"",
"taskkill /im sshd.exe /f"
]
},
{
"type": "shell",
"pause_before": "30s",
"inline": [ "rm -rf /tmp/*" ]
}
]
}
Running on Windows 7 Enterprise 64-bit (with PACKER_LOG=1):
packer.exe build -force -var "name=winVistax64-enterprise" winVistax64-enterprise\packer.json
This will create the virtual machine, and run all the provisioning steps (ex. install vmware tools), but will fail when trying to run the shutdown_command as follows:
2015/11/17 15:52:26 ui: ==> winVistax64-enterprise: Gracefully halting virtual machine...
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: 2015/11/17 15:52:26 Executing shutdown command: reg export HKLM\System\MountedDevices MountedDevices.reg
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: 2015/11/17 15:52:26 opening new ssh session
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: 2015/11/17 15:52:26 starting remote command: reg export HKLM\System\MountedDevices MountedDevices.reg
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: 2015/11/17 15:52:26 remote command exited with '0': reg export HKLM\System\MountedDevices MountedDevices.reg
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: 2015/11/17 15:52:26 Shutdown stdout: ERROR: Invalid key name.
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: Type "REG EXPORT /?" for usage.
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: 2015/11/17 15:52:26 Shutdown stderr:
2015/11/17 15:52:26 packer-builder-vmware-iso.exe: 2015/11/17 15:52:26 Waiting max 15m0s for shutdown to complete
Manually running the command reg export HKLM\System\MountedDevices MountedDevices.reg inside the guest works as expected.
Any ideas?
Thank you.
Heyo! This is two circuits outside my usual stomping grounds, but two thoughts:
"shutdown_command": "reg export HKLM\\\\System\\\\MountedDevices MountedDevices.reg",
MountedDevices.reg a file? Does the guest have access to this file on disk? Maybe you need to specify the absolute path to this file.1.
I also tried double-escaping the backslashes, but it resulted in the same issue:
2015/11/17 17:37:07 ui: ==> winVistax64-enterprise: Gracefully halting virtual machine...
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: 2015/11/17 17:37:07 Executing shutdown command: reg export HKLM\\System\\MountedDevices MountedDevices.reg
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: 2015/11/17 17:37:07 opening new ssh session
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: 2015/11/17 17:37:07 starting remote command: reg export HKLM\\System\\MountedDevices MountedDevices.reg
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: 2015/11/17 17:37:07 remote command exited with '0': reg export HKLM\\System\\MountedDevices MountedDevices.reg
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: 2015/11/17 17:37:07 Shutdown stdout: ERROR: Invalid key name.
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: Type "REG EXPORT /?" for usage.
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: 2015/11/17 17:37:07 Shutdown stderr:
2015/11/17 17:37:07 packer-builder-vmware-iso.exe: 2015/11/17 17:37:07 Waiting max 15m0s for shutdown to complete
2.
MountedDevices.reg is a file that will get created as a result of running that command.
If reg.exe was not able to write the file, I would expect a different error.
For ex. ERROR: Unable to write to the file. There may be a disk or file system error.
I also tried specifying a full path anyway but the results are not any different:
Json:
"shutdown_command": "reg export HKLM\\System\\MountedDevices c:/windows/temp/MountedDevices.reg"
Log:
2015/11/17 18:55:35 ui: ==> winVistax64-enterprise: Gracefully halting virtual machine...
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: 2015/11/17 18:55:35 Executing shutdown command: reg export HKLM\System\MountedDevices c:/windows/temp/MountedDevices.reg
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: 2015/11/17 18:55:35 opening new ssh session
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: 2015/11/17 18:55:35 starting remote command: reg export HKLM\System\MountedDevices c:/windows/temp/MountedDevices.reg
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: 2015/11/17 18:55:35 remote command exited with '0': reg export HKLM\System\MountedDevices c:/windows/temp/MountedDevices.reg
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: 2015/11/17 18:55:35 Shutdown stdout: ERROR: Invalid key name.
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: Type "REG EXPORT /?" for usage.
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: 2015/11/17 18:55:35 Shutdown stderr:
2015/11/17 18:55:35 packer-builder-vmware-iso.exe: 2015/11/17 18:55:35 Waiting max 15m0s for shutdown to complete
Manually running the command reg export HKLM\System\MountedDevices c:/windows/temp/MountedDevices.reg in the guest works as expected too.
Thank you.
Also, running that command using PuTTY also works as expected.
Any other ideas?
Thank you.
The same thing happens for a provisioner shell script:
{
"type": "shell",
"remote_path": "/tmp/script.bat",
"execute_command": "C:/Windows/Temp/script.bat hello\\\\world",
"scripts": [
"scripts/test.bat"
]
}
test.bat:
@rem test.bat
@echo on
echo %*
msg * /W %*
helloworld is displayed.
I discovered a workaround is to use triple backslashes in execute_command, but that doesn't seem to work for shutdown_command.
"execute_command": "C:/Windows/Temp/script.bat hello\\\\\\world"
displays hello\world
It seems that I can't use an asterisk in the shutdown_command:
"shutdown_command": "msg /TIME:0 /V /W Administrator hello world"
displays hello world
"shutdown_command": "msg /TIME:0 /V /W Administrator hello * world"
produces:
2015/11/22 09:53:57 packer.exe: 2015/11/22 09:53:57 opening new ssh session
2015/11/22 09:53:57 packer.exe: 2015/11/22 09:53:57 starting remote command: msg /TIME:0 /V /W Administrator hello * world
2015/11/22 09:53:57 packer.exe: 2015/11/22 09:53:57 remote command exited with '0': msg /TIME:0 /V /W Administrator hello * world
2015/11/22 09:53:57 packer.exe: 2015/11/22 09:53:57 Shutdown stdout:
2015/11/22 09:53:57 packer.exe: 2015/11/22 09:53:57 Shutdown stderr: Invalid parameter(s)
2015/11/22 09:53:57 packer.exe: Send a message to a user.
2015/11/22 09:53:57 packer.exe:
2015/11/22 09:53:57 packer.exe: MSG {username | sessionname | sessionid | @filename | *}
2015/11/22 09:53:57 packer.exe: [/SERVER:servername] [/TIME:seconds] [/V] [/W] [message]
2015/11/22 09:53:57 packer.exe:
2015/11/22 09:53:57 packer.exe: username Identifies the specified username.
2015/11/22 09:53:57 packer.exe: sessionname The name of the session.
2015/11/22 09:53:57 packer.exe: sessionid The ID of the session.
2015/11/22 09:53:57 packer.exe: @filename Identifies a file containing a list of usernames,
2015/11/22 09:53:57 packer.exe: sessionnames, and sessionids to send the message to.
2015/11/22 09:53:57 packer.exe: * Send message to all sessions on specified server.
2015/11/22 09:53:57 packer.exe: /SERVER:servername server to contact (default is current).
2015/11/22 09:53:57 packer.exe: /TIME:seconds Time delay to wait for receiver to acknowledge msg.
2015/11/22 09:53:57 packer.exe: /V Display information about actions being performed.
2015/11/22 09:53:57 packer.exe: /W Wait for response from user, useful with /V.
2015/11/22 09:53:57 packer.exe: message Message to send. If none specified, prompts for it
2015/11/22 09:53:57 packer.exe: or reads from stdin.
2015/11/22 09:53:57 packer.exe:
2015/11/22 09:53:57 packer.exe: 2015/11/22 09:53:57 Waiting max 15m0s for shutdown to complete
It works fine on the command line on the machine itself and also using the PuTTY SSH client.
I also can't use start:
"shutdown_command": "start /wait msg /TIME:0 /V /W Administrator hello world"
produces:
2015/11/22 11:38:44 ui: ==> winVistax64-enterprise: Gracefully halting virtual machine...
2015/11/22 11:38:44 packer.exe: 2015/11/22 11:38:44 Executing shutdown command: start /wait msg /TIME:0 /V /W Administrator hello world
2015/11/22 11:38:44 packer.exe: 2015/11/22 11:38:44 opening new ssh session
2015/11/22 11:38:44 packer.exe: 2015/11/22 11:38:44 starting remote command: start /wait msg /TIME:0 /V /W Administrator hello world
2015/11/22 11:38:44 packer.exe: 2015/11/22 11:38:44 remote command exited with '0': start /wait msg /TIME:0 /V /W Administrator hello world
2015/11/22 11:38:44 packer.exe: 2015/11/22 11:38:44 Shutdown stdout:
2015/11/22 11:38:44 packer.exe: 2015/11/22 11:38:44 Shutdown stderr: /bin/sh: start: command not found
2015/11/22 11:38:44 packer.exe: 2015/11/22 11:38:44 Waiting max 15m0s for shutdown to complete
I also can't use del to delete a file:
2015/11/23 01:21:55 packer.exe: /bin/sh: del: command not found
This also happens when using a compiled version of the latest source code, 0.9.0 (pre-release)
Yes, it seems that a triple backslash also works when used in shutdown_command
There seems to be a limit of 238 characters for the shutdown_command
"shutdown_command": "msg /TIME:0 /V /W Administrator Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis nunc elit, a semper nisi euismod vitae. In euismod ligula enim, et iaculis odio rhoncus at. Suspendisse mi libero, porta eu congue sit amet, lacinia a nisi. Aliquam erat volutpat. Cras id lorem quam.",
displays the following message:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis nunc elit, a semper nisi euismod vitae. In euismod ligula enim, et iaculis odio rhoncus at. Suspendisse mi libero, porta eu congue sit am
This issue is old, but ftr: commands like start and del are actually part of the cmd.exe prompt. So you need to run them with cmd.exe /c start ...whatever... or cmd.exe /c del ...whatever....
So, the issue with being unable to use asterisk or the necessity of the triple backslash is because cygwin's bourne shell is pre-processing the command before executing it. So, for asterisk, the shell is expanding it to all the files in the cwd. If you escape the asterisk with "\" or single-quote it, that should get it passed to reg.exe without issue.
The issue with needing a ton of backslashes are also related to the shell. If you single-quote your registry key argument, the shell will avoid processing them. If you change your shell to be cmd.exe, things will probably work as you expect them to.
Also fyi, because ms-dos batch files are micro$oft (and they're pretty crazy). Your escape character for running things on cmd.exe is not "\" but actually "^".
Sounds like this issue is more about knowing how to escape nested shells than about something that Packer is likely to be able to fix. I'm closing for now, but if anyone has concrete ideas about what they'd like to see Packer do to fix this, I'd love to hear them.
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.
Most helpful comment
This issue is old, but ftr: commands like
startanddelare actually part of thecmd.exeprompt. So you need to run them withcmd.exe /c start ...whatever...orcmd.exe /c del ...whatever....So, the issue with being unable to use asterisk or the necessity of the triple backslash is because cygwin's bourne shell is pre-processing the command before executing it. So, for asterisk, the shell is expanding it to all the files in the cwd. If you escape the asterisk with "\" or single-quote it, that should get it passed to
reg.exewithout issue.The issue with needing a ton of backslashes are also related to the shell. If you single-quote your registry key argument, the shell will avoid processing them. If you change your shell to be cmd.exe, things will probably work as you expect them to.
Also fyi, because ms-dos batch files are micro$oft (and they're pretty crazy). Your escape character for running things on cmd.exe is not "\" but actually "^".