atlas-packer-vagrant-tutorial icon indicating copy to clipboard operation
atlas-packer-vagrant-tutorial copied to clipboard

Windows-friendly tutorial

Open curtismitchell opened this issue 9 years ago • 19 comments

Hey -

I went through the tutorial on a Windows box. The instruction to export the environment variable doesn't work in the default command window or powershell. Also, AFAIK, curl isn't that widely used on Windows.

I changed "export" to "set" to add the environment variable. Luckily, I also have curl. But, the build failed. I'm using this repo for the build. Could it be caused by the bash scripts which aren't supported in my shell?

curtismitchell avatar Apr 20 '15 17:04 curtismitchell

I ran into similar issues, but I was able to add the environment variable without a problem because I was using Git Bash to execute the command. I've tried the example tutorial using Windows CMD and Git Bash with mixed results. For example, running the command packer push template.json from CMD returns this output:

Push target doesn't exist: example. Either create this online via the website or pass the -create flag.

_BEGIN UPDATE_

I discovered why I was getting the output above, it seems that even after executing

SET ATLAS_TOKEN="J_qMfVVviSy__U1n_2YX7ckV1qM6tquxXi2pk6n69yQqyP...

The environment variable wasn't added (or at least listed), so I did this manually through Windows UI and was able to execute the command successfully (using CMD) immediately after. I think the issue here is that the output doesn't really tell the user that there's a problem. I wasn't informed of a problem until I tried running the command with the -create flag, which told me there was an authentication issue or the ATLAS_TOKEN wasn't defined.

_END UPDATE_

If I run the same command from within Git Bash I get this output:

Push successful to 'ontic/example'

Then when I check the build configuration output on https://atlas.hashicorp.com it display this:

---- Started new build at 2015-06-02 14:42:01.031413132 +0000 UTC ----
Packer v0.7.5

virtualbox-iso output will be in this color.

7 error(s) occurred:

* Bad script 'scripts/base.sh': stat scripts/base.sh: no such file or directory
* Bad script 'scripts/virtualbox.sh': stat scripts/virtualbox.sh: no such file or directory
* Bad script 'scripts/vmware.sh': stat scripts/vmware.sh: no such file or directory
* Bad script 'scripts/vagrant.sh': stat scripts/vagrant.sh: no such file or directory
* Bad script 'scripts/dep.sh': stat scripts/dep.sh: no such file or directory
* Bad script 'scripts/cleanup.sh': stat scripts/cleanup.sh: no such file or directory
* Bad script 'scripts/zerodisk.sh': stat scripts/zerodisk.sh: no such file or directory

ontic avatar Jun 02 '15 14:06 ontic

@ontic it seems like the files in scripts aren't being sent with packer push along with the template. Those files need to be sent to Atlas.

In the push configuration, can you set the field "vcs:false" and let me know if the files get sent up properly? http://www.packer.io/docs/templates/push.html#vcs

KFishner avatar Jun 02 '15 16:06 KFishner

@KFishner Thanks for your help, adding the vcs option made no difference. But you lead me to the template documentation where I came across the option base_dir. Below is part of my template.json file which did work (sort of).

{
    "push": {
      "name": "ontic/example",
      "vcs": false,
      "base_dir": "C:/Users/Adam/Packer/Tutorial/atlas-packer-vagrant-tutorial/scripts/"
    },
    "variables": {
        "atlas_username": "{{env `ATLAS_USERNAME`}}",
        "atlas_name": "{{env `ATLAS_NAME`}}"
    },
    "provisioners": [
        {
            "type": "shell",
            "scripts": [
                "base.sh",
                "virtualbox.sh",
                "vmware.sh",
                "vagrant.sh",
                "dep.sh",
                "cleanup.sh",
                "zerodisk.sh"
            ],
            ...

I was exited to see the build running after making those changes, however it comes to a halt when waiting for SSH to become available. Below is the output:

---- Started new build at 2015-06-03 00:27:19.046794833 +0000 UTC ----
Packer v0.7.5

virtualbox-iso output will be in this color.

==> virtualbox-iso: Cannot find "Default Guest Additions ISO" in vboxmanage output (or it is empty)
==> virtualbox-iso: Downloading or copying Guest additions checksums
    virtualbox-iso: Downloading or copying: http://download.virtualbox.org/virtualbox/4.3.10/SHA256SUMS
==> virtualbox-iso: Downloading or copying Guest additions
    virtualbox-iso: Downloading or copying: http://download.virtualbox.org/virtualbox/4.3.10/VBoxGuestAdditions_4.3.10.iso
==> virtualbox-iso: Downloading or copying ISO
    virtualbox-iso: Downloading or copying: http://releases.ubuntu.com/precise/ubuntu-12.04.5-server-amd64.iso
    virtualbox-iso: Download progress: 15%
    virtualbox-iso: Download progress: 44%
    virtualbox-iso: Download progress: 100%
==> virtualbox-iso: Starting HTTP server on port 8662
==> virtualbox-iso: Creating virtual machine...
==> virtualbox-iso: Creating hard drive...
==> virtualbox-iso: Creating forwarded port mapping for SSH (host port 3611)
==> virtualbox-iso: Starting the virtual machine...
    virtualbox-iso: WARNING: The VM will be started in headless mode, as configured.
    virtualbox-iso: In headless mode, errors during the boot sequence or OS setup
    virtualbox-iso: won't be easily visible. Use at your own discretion.
==> virtualbox-iso: Waiting 10s for boot...
==> virtualbox-iso: Typing the boot command...
==> virtualbox-iso: Waiting for SSH to become available...

ontic avatar Jun 03 '15 00:06 ontic

hmmm @ontic that's odd — I just ran this build and it worked fine. How long did you wait for SSH to become available?

KFishner avatar Jun 03 '15 19:06 KFishner

I have also tried following the tutorial on a Windows machine (Windows 7 x64 Professsional). I made the following changes to the template.json.

diff --git a/template.json b/template.json
index f0e3433..6503a26 100644
--- a/template.json
+++ b/template.json
@@ -1,6 +1,8 @@
 {
     "push": {
-      "name": ""
+      "name": "nigelw/example",
+      "vcs": false,
+      "base_dir": "H:/workspace/atlas-packer-vagrant-tutorial/scripts/"
     },
     "variables": {
         "atlas_username": "{{env `ATLAS_USERNAME`}}",
@@ -10,13 +12,13 @@
         {
             "type": "shell",
             "scripts": [
-                "scripts/base.sh",
-                "scripts/virtualbox.sh",
-                "scripts/vmware.sh",
-                "scripts/vagrant.sh",
-                "scripts/dep.sh",
-                "scripts/cleanup.sh",
-                "scripts/zerodisk.sh"
+                "base.sh",
+                "virtualbox.sh",
+                "vmware.sh",
+                "vagrant.sh",
+                "dep.sh",
+                "cleanup.sh",
+                "zerodisk.sh"
             ],
             "override": {
                 "virtualbox-iso": {

Both the virtualbox and vmware builds have stopped at the same place.

---- Started new build at 2015-06-20 20:27:33.426618441 +0000 UTC ----
Packer v0.7.5

virtualbox-iso output will be in this color.

==> virtualbox-iso: Downloading or copying Guest additions
    virtualbox-iso: Downloading or copying: file:///usr/share/virtualbox/VBoxGuestAdditions.iso
==> virtualbox-iso: Downloading or copying ISO
    virtualbox-iso: Downloading or copying: http://releases.ubuntu.com/precise/ubuntu-12.04.5-server-amd64.iso
    virtualbox-iso: Download progress: 18%
    virtualbox-iso: Download progress: 51%
    virtualbox-iso: Download progress: 100%
==> virtualbox-iso: Starting HTTP server on port 8900
==> virtualbox-iso: Creating virtual machine...
==> virtualbox-iso: Creating hard drive...
==> virtualbox-iso: Creating forwarded port mapping for SSH (host port 3440)
==> virtualbox-iso: Starting the virtual machine...
    virtualbox-iso: WARNING: The VM will be started in headless mode, as configured.
    virtualbox-iso: In headless mode, errors during the boot sequence or OS setup
    virtualbox-iso: won't be easily visible. Use at your own discretion.
==> virtualbox-iso: Waiting 10s for boot...
==> virtualbox-iso: Typing the boot command...
==> virtualbox-iso: Waiting for SSH to become available...

This is after 2 hours.

nwns avatar Jun 20 '15 22:06 nwns

It seems to have failed after 3 hours with the below text.

==> virtualbox-iso: Timeout waiting for SSH.
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Timeout waiting for SSH.

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.

nwns avatar Jun 20 '15 23:06 nwns

@nwns @ontic thanks for sending this over. I think the issue is that the reference to the preseed.cfg is broken with your current base_dir setup: https://github.com/hashicorp/atlas-packer-vagrant-tutorial/blob/master/template.json#L36

This file is necessary to setup the VM for SSH. As you can see, it uses a reference to the http dir, which is missed if you set the base_dir to H:/workspace/atlas-packer-vagrant-tutorial/scripts/. My recommendation is to set the base_dir to H:/workspace/atlas-packer-vagrant-tutorial/ and update the provisioning block back to scripts/base.sh, scripts/virtualbox.sh, etc.

That way when you packer push, it will send up the http directory as well, which can then be referenced in the boot_command.

Let me know if this works!

KFishner avatar Jun 22 '15 14:06 KFishner

@KFishner Doing that results in the issue mentioned originally.

7 error(s) occurred:

* Bad script 'scripts/base.sh': stat scripts/base.sh: no such file or directory
* Bad script 'scripts/virtualbox.sh': stat scripts/virtualbox.sh: no such file or directory
* Bad script 'scripts/vmware.sh': stat scripts/vmware.sh: no such file or directory
* Bad script 'scripts/vagrant.sh': stat scripts/vagrant.sh: no such file or directory
* Bad script 'scripts/dep.sh': stat scripts/dep.sh: no such file or directory
* Bad script 'scripts/cleanup.sh': stat scripts/cleanup.sh: no such file or directory
* Bad script 'scripts/zerodisk.sh': stat scripts/zerodisk.sh: no such file or directory

If I change the direction of the slashes it then works and I can push, but it still seems to hang (it has been running for 30 minutes waiting for SSH).

diff --git a/template.json b/template.json
index f0e3433..5fd2f39 100644
--- a/template.json
+++ b/template.json
@@ -1,6 +1,8 @@
 {
     "push": {
-      "name": ""
+      "name": "nigelw/example",
+      "vcs": false,
+      "base_dir": "H:/workspace/atlas-packer-vagrant-tutorial/"
     },
     "variables": {
         "atlas_username": "{{env `ATLAS_USERNAME`}}",
@@ -10,13 +12,13 @@
         {
             "type": "shell",
             "scripts": [
-                "scripts/base.sh",
-                "scripts/virtualbox.sh",
-                "scripts/vmware.sh",
-                "scripts/vagrant.sh",
-                "scripts/dep.sh",
-                "scripts/cleanup.sh",
-                "scripts/zerodisk.sh"
+                "scripts\\base.sh",
+                "scripts\\virtualbox.sh",
+                "scripts\\vmware.sh",
+                "scripts\\vagrant.sh",
+                "scripts\\dep.sh",
+                "scripts\\cleanup.sh",
+                "scripts\\zerodisk.sh"
             ],
             "override": {
                 "virtualbox-iso": {

Interestingly, if I packer build -only virtualbox-iso template.json the build completes and fails at the push to atlas step (because the ENV variables are missing). I am using Virtualbox 4.3.20.

nwns avatar Jun 23 '15 01:06 nwns

cool thanks for the update @nwns. Did you try changing the reference to the http dir?

KFishner avatar Jun 23 '15 03:06 KFishner

Yes, I pushed what changes I had to make to a5360a18a9a96d9c29b65000b4ab9e8241760932.

It seems to work now for Virtual Box on Atlas, but the VMWare build is hanging with the same waiting for SSH to become available.

As an aside, I am had a similar problem with the new base that I created yesterday for SmartOS (found: https://github.com/nwns/vagrant-smartos-host). I just skipped using a VMWare builder for my SmartOS one because I have no way to troubleshoot it.

nwns avatar Jun 23 '15 03:06 nwns

Hmm apologies if this is an obvious question, but it looks like you changed the http dir reference in the virtualbox-iso builder, but not the vmware-iso builder. That could be the issue if you didn't test that out

KFishner avatar Jun 23 '15 12:06 KFishner

Yep, you are correct. I missed that.

Changing it fixed the vmware build, thanks

nwns avatar Jun 27 '15 03:06 nwns

Wish I'd looked in here first, could of saved myself a couple of days :)

Can confirm those fixes as required to run it under a Windows development environment. https://github.com/jedineeper/atlas-packer-vagrant-tutorial/commit/89b290bc038321ff20ef41c1848ded04c32677a5

jedineeper avatar Jun 29 '15 11:06 jedineeper

I went through the atlas tutorial on Windows and eventually got through but I had to change a few things.

When I performed the instructions for exporting the atlas token I changed export to "set" but I also had to remove the quotes from around the value. If the quotes are in there the packer push doesn't work. I eventually figured out they were causing a problem when I did "vagrant login" (which worked) and then did "vagrant login --check" which got a bad uri error due to the quotes from the %ATLAS_TOKEN% environment variable. When I removed the quotes I was able to run vagrant login --check and then the packer push worked.

I also had to change the curl url to use %ATLAS_TOKEN% instead of $ATLAS_TOKEN.

I think with a couple minor changes the tutorial could be made to work fairly smoothly on windows, assuming people have curl installed.

  1. Provide set ATLAS_TOKEN=asdf (no quotes, set vs. export)
  2. Provide curl command with variable as %ATLAS_TOKEN% instead of $ATLAS_TOKEN

hdeadman avatar Aug 13 '15 16:08 hdeadman

@hdeadman Thanks a lot for this. We can check OS with JavaScript and conditionally fix some of these issues. Appreciate you and others in the thread for bringing it to our attention!

pearkes avatar Aug 13 '15 17:08 pearkes

+1 :dancers:

kikitux avatar Aug 24 '15 09:08 kikitux

+1

ghost avatar Oct 10 '15 20:10 ghost

Another note, using packer 0.9.0 on Windows in PowerShell, I was able to get the tutuorial example to work without modifying template.json, like so:

$env:ATLAS_TOKEN="abcdef"
packer push -name accountname/example ./template.json

The key for me was in the template documentation, where it says that the base_dir is relative to the template. If you don't include the ./ in the path to the template, then the relative path fails and the build fails with the errors in original post.

lorengordon avatar Mar 11 '16 14:03 lorengordon

@lorengordon Thanks! This worked for me in PowerShell on Windows 10, Packer v0.10.1

ghost avatar Sep 09 '16 22:09 ghost