mitchellh / veewee-to-packer

A tool for converting Veewee templates into Packer templates.
http://www.packer.io
MIT License
66 stars 14 forks source link

postinstall script ends up in ~/tmp not /tmp/postinstall.sh -- packer build failed with a template created by veewee-to-packer #9

Closed jerryasher closed 11 years ago

jerryasher commented 11 years ago

I started with a @ejholmes vagrant-heroku veewee template. Specifically, the definition.rb, preseed.cfg (ubuntu kickstart) and postinstall.sh that are found here: https://github.com/ejholmes/vagrant-heroku/tree/master/definitions/heroku

I ran veewee-to-packer on them (in a Win 7 64 cmd.exe box that has Ruby.1.9.3 installed) and veewee-to-packer ran almost cleanly with one non-critical error

C:\Users\jerry\d\gits\vagrant-heroku-1\definitions\heroku>ruby --version
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

C:\Users\jerry\d\gits\vagrant-heroku-1\definitions\heroku>veewee-to-packer definition.rb
There were some non-critical warnings during the conversion process.
Your template will function despite these warnings, but they're noted
here so you can understand some aspects of the Veewee definition that
may not have carried over perfectly to the Packer template:

* ':postinstall_timeout' doesn't exist in Packer.

Success! Your Veewee definition was converted to a Packer template!
The template can be found in the `template.json` file in the output
directory: output

Please be sure to run `packer validate` against the new template
to verify settings are correct.

C:\Users\jerry\d\gits\vagrant-heroku-1\definitions\heroku>

I took the template it created, and deleted the vmware section. (I realize now I could have just used a flag to ignore it.)

The template used can be found here: https://gist.github.com/jerryasher/5957147

When I ran packer build, it created a VirtualBox VM and started it up and seemed to run through the kickstart correctly.

But in the end there were errors. I don't know if the errors relate to the postinstall_timeout not existing, or if there were other problems.

The stdout log is:

←[0;32;40mvirtualbox: Download progress: 100%←[0m
←[0;32;40mvirtualbox: Download progress: 100%←[0m
←[1;32;40m==> virtualbox: Starting HTTP server on port 8081←[0m
←[1;32;40m==> virtualbox: Creating virtual machine...←[0m
←[1;32;40m==> virtualbox: Creating hard drive...←[0m
←[1;32;40m==> virtualbox: Creating forwarded port mapping for SSH (host port 3213)←[0m
←[1;32;40m==> virtualbox: Executing custom VBoxManage commands...←[0m
←[0;32;40mvirtualbox: Executing: modifyvm packer-virtualbox --memory 512←[0m
←[0;32;40mvirtualbox: Executing: modifyvm packer-virtualbox --cpus 1←[0m
←[1;32;40m==> virtualbox: Starting the virtual machine...←[0m
←[1;32;40m==> virtualbox: Waiting 10s for boot...←[0m
←[1;32;40m==> virtualbox: Typing the boot command...←[0m
←[1;32;40m==> virtualbox: Waiting for SSH to become available...←[0m
←[1;32;40m==> virtualbox: Connected via SSH!←[0m
←[1;32;40m==> virtualbox: Uploading VirtualBox version info (4.2.12)←[0m
←[1;32;40m==> virtualbox: Uploading VirtualBox guest additions ISO...←[0m
←[1;32;40m==> virtualbox: Provisioning with shell script: scripts/postinstall.sh←[0m
←[0;32;40mvirtualbox: [sudo] password for vagrant: sh: Can't open /tmp/script.sh←[0m
←[1;31;40m==> virtualbox: Error unregistering ISO: VBoxManage error: VBoxManage.exe: error: Controller 'IDE Controller'
does not support hotplugging
==> virtualbox: VBoxManage.exe: error: Details: code VBOX_E_INVALID_VM_STATE (0x80bb0002), component SessionMachine, int
erface IMachine, callee IUnknown
==> virtualbox: VBoxManage.exe: error: Context: "DetachDevice(Bstr(pszCtl).raw(), port, device)" at line 381 of file VBo
xManageStorageController.cpp←[0m
←[1;32;40m==> virtualbox: Unregistering and deleting virtual machine...←[0m
←[1;31;40m==> virtualbox: Error deleting virtual machine: VBoxManage error: VBoxManage.exe: error: Cannot unregister the
 machine 'packer-virtualbox' while it is locked
==> virtualbox: VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interf
ace IMachine, callee IUnknown
==> virtualbox: VBoxManage.exe: error: Context: "Unregister(fDelete ? (CleanupMode_T)CleanupMode_DetachAllReturnHardDisk
sOnly : (CleanupMode_T)CleanupMode_DetachAllReturnNone, ComSafeArrayAsOutParam(aMedia))" at line 160 of file VBoxManageM
isc.cpp←[0m
←[1;32;40m==> virtualbox: Deleting output directory...←[0m
←[1;31;40mBuild 'virtualbox' errored: Script exited with non-zero exit status: 2←[0m

==> Some builds didn't complete successfully and had errors:
--> virtualbox: Script exited with non-zero exit status: 2

==> Builds finished but no artifacts were created.

C:\Users\jerry\d\gits\vagrant-heroku\definitions\heroku\output>dir

As you can see, it first had a problem finding /tmp/script.sh

On the VM when I log in the /tmp directory is empty, BUT in /home/vagrant there is a file named tmp that contains the postinstall.sh script.

So I am not sure if this is a veewee-to-packer issue, a packer issue, or something I did.

Also, I am relatively new to github, so I apologize if there was a better way to communicate all this stuff to you,

Thanks

mitchellh commented 11 years ago

Can you post the output with PACKER_LOG set to 1? (to get verbose output)

Please gist it, since it will be loud.

jerryasher commented 11 years ago

Hi Mitchell,

Thanks for your help. I am rerunning this now.

I hope you don't mind a few newbie questions. I have a few issues with how packer works, though it is probably trying this on windows. As issues arise would you prefer I a) email you, b) discuss them on the google group, or c) add them as issues to github?

  1. xterm/curses cruft in the logs

Anyway, I am using the native ruby for windows installed into c:\Ruby193. It's a bizarre creature in that if I run a rubyish command like veewee-to-packer from a cygwin shell, the ruby app can't find ruby (seemingly if it needs to shell out). So I have to run ruby apps from cmd.exe.

But, it seems as though packer likes to think it is in some form of xterm as it logs its messages. Is there an easy way to tell it not to use the curses cursor manipulation stuff?

←[0;32;40mvirtualbox: Download progress: 19%←[0m 2013/07/09 19:52:17 ui: ←[0;32;40mvirtualbox: Download progress: 19%←[0m

  1. downloads of isos placed in packer_cache are given some form of hashed name

Downloads of isos placed in packer_cache are given some form of hashed name. Is there anything I can place in a builder specification to let packer know where on disk the iso already lives?

3, packer cleanup

Is there an easy way to cleanup after a failed run to start again?

Thanks,

Jerry

On Tue, Jul 9, 2013 at 4:17 PM, Mitchell Hashimoto <notifications@github.com

wrote:

Can you post the output with PACKER_LOG set to 1? (to get verbose output)

Please gist it, since it will be loud.

— Reply to this email directly or view it on GitHubhttps://github.com/mitchellh/veewee-to-packer/issues/9#issuecomment-20712219 .

mitchellh commented 11 years ago

Jerry,

These questions are really best suited for the mailing list as they have no relevance at all to the issue at hand. I'll answer them this time, but please use the mailing list next time.

  1. Seems like two questions. re: Ruby, I have no idea. v2p is a very vanilla RubyGem and I don't know why it would do that. Ruby on Windows is pretty scary. As for the xterm stuff, Packer currently outputs colors. There isn't a way to disable this at the moment.
  2. The "iso_url" field can take a file path.
  3. Packer will clean itself up unless it crashes (which would be a major bug). But in the case of failed runs, it cleans up. In the case of the output above, it looks like it failed to properly undo some things. I'll look into that.
jerryasher commented 11 years ago

Hi Mitchell,

I think this is a bug -- if you agree and would prefer I can write it up as a github issue.

Jerry

Regarding the iso_url field being a local file, in my template.json, none of the following seemed to validate for the value of "iso_url":

"c:\ISOs\ubuntu.iso" --> * Unsupported URL scheme in iso_url: c

"c:\ISOs\ubuntu.iso" --> Failed to parse template: Error in line 35, char 21: invalid character 'I' in string escape code "iso_url": "c:\ISOS\ubuntu-10.04.4-server-amd64.iso",

"c:/ISOs/ubuntu.iso" --> * Unsupported URL scheme in iso_url: c

"c://ISOs//ubuntu.iso" --> * Unsupported URL scheme in iso_url: c

I copied the iso into the directory of the template.json file and placed in the template.json file

"iso_url": "ubuntu-10.04.4-server-amd64.iso",

That did validate, but when I ran packer build template.json, I got this:

2013/07/10 02:22:07 C:\HashiCorp\Vagrant\bin\packer-builder-virtualbox.exe: 2013/07/10 02:22:07 Parsed URL: &url.URL{Scheme:"file", Opaque:"", User:(*url.Userinfo)(nil), Host:"ubuntu-10.04.4-server-amd64.iso", Path:"", RawQuery:"", Fragment:""} 2013/07/10 02:22:07 ui error: ==> virtualbox: Error downloading ISO: open : The system cannot find the file specified. ==> virtualbox: Error downloading ISO: open : The system cannot find the file specified. 2013/07/10 02:22:07 ui error: Build 'virtualbox' errored: Error downloading ISO: open : The system cannot find the file specified. Build 'virtualbox' errored: Error downloading ISO: open : The system cannot find the file specified. 2013/07/10 02:22:07 ui error: ==> Some builds didn't complete successfully and had errors:

Again, that validated with packer validate template.json, but it would not build.

Should a windows file path for iso_url be supported? If so, can you provide an example of one that works?

Jerry

On Tue, Jul 9, 2013 at 8:05 PM, Mitchell Hashimoto <notifications@github.com

wrote:

Jerry,

These questions are really best suited for the mailing list as they have no relevance at all to the issue at hand. I'll answer them this time, but please use the mailing list next time.

1.

Seems like two questions. re: Ruby, I have no idea. v2p is a very vanilla RubyGem and I don't know why it would do that. Ruby on Windows is pretty scary. As for the xterm stuff, Packer currently outputs colors. There isn't a way to disable this at the moment. 2.

The "iso_url" field can take a file path. 3.

Packer will clean itself up unless it crashes (which would be a major bug). But in the case of failed runs, it cleans up. In the case of the output above, it looks like it failed to properly undo some things. I'll look into that.

— Reply to this email directly or view it on GitHubhttps://github.com/mitchellh/veewee-to-packer/issues/9#issuecomment-20719132 .

jerryasher commented 11 years ago

Hi Mitchell,

I created the very loud log file. You can find it here: https://gist.github.com/jerryasher/5965395

Thanks,

Jerry

levpaul commented 11 years ago

I'm experiencing something similar in my setup.

virtualbox: [sudo] password for vagrant: sh: Can't open /tmp/script.sh←[0m
←[1;31;40m==> virtualbox: Error unregistering ISO: VBoxManage error: VBoxManage.exe: error: Controller 'IDE Controller'
does not support hotplugging
==> virtualbox: VBoxManage.exe: error: Details: code VBOX_E_INVALID_VM_STATE (0x80bb0002), component SessionMachine, int
erface IMachine, callee IUnknown
==> virtualbox: VBoxManage.exe: error: Context: "DetachDevice(Bstr(pszCtl).raw(), port, device)" at line 381 of file VBo
xManageStorageController.cpp←[0m
←[1;32;40m==> virtualbox: Unregistering and deleting virtual machine...←[0m
←[1;31;40m==> virtualbox: Error deleting virtual machine: VBoxManage error: VBoxManage.exe: error: Cannot unregister the
 machine 'packer-virtualbox' while it is locked
==> virtualbox: VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interf
ace IMachine, callee IUnknown
levpaul commented 11 years ago

I kind of suspect that packer is having trouble moving the script to the correct location as on the box I see the script inside the home directory of vagrant named as 'tmp' or something. I'll try to dig around this weekend to see if I can see anything.

mitchellh commented 11 years ago

I actually think this is fixed with this commit in Packer:

https://github.com/mitchellh/packer/commit/41df9fa2e8fa8be6604a1a9e5b8a53d83dedb423

levpaul commented 11 years ago

Woohooooooo!!!!!!!! The said fix works magnificently. Thanks!