packer-community / packer-windows-plugins

A suite of Packer plugins for provisioning Windows machines
113 stars 20 forks source link

Concatenating inline scripts into a temporary file fails on Windows hosts #21

Closed zl4bv closed 9 years ago

zl4bv commented 9 years ago

With the current code, the following error occurs when executing Packer on Windows with the powershell provisioner and the windows shell provisioner:

==> virtualbox-windows-iso: Unable to extract inline scripts into a file: open \tmp\packer-powershell-provisioner199224447: The system cannot find the path specified.

Windows interprets this path as C:\tmp\packer-powershell-provisioner199224447 assuming your current working directory was on C: drive when you executed packer (D:\tmp\ ... if you're currently on D: drive). In normal circumstances C:\tmp\ directory doesn't exist - but creating the directory is a quick hack to solve the error above.

The changes in this PR make use of the os.TempDir method which is a platform independent way of getting the default temporary directory. On *NIX the temporary directory will continue to be /tmp/ but on Windows it will change to something like below:

==> virtualbox-windows-iso: Provisioning with shell script: C:\Users\Ben\AppData\Local\Temp\packer-powershell-provisioner003844411
mefellows commented 9 years ago

Thanks Ben, I'll take a look at this a bit later today.

Whilst the changes look completely reasonable, I'm curious as to why the current situation is not working for you as we've not seen any issues related to this. Any context you could provide would be fantastic to help with future issues (e.g. Host machine, Windows version, sample packer.json etc.)

zl4bv commented 9 years ago

Hi Matt, my host machine is running Windows 7 Enterprise 64-bit and I have compiled my own binaries using the latest commit of packer-community/packer-windows-plugins.

I am trying to create a build with Windows Server 2008 R2 Standard 64-bit - however this should not be relevant because it's failing to combine the inline scripts which is done on the host.

Here is an example packer JSON:

{
  "builders": [{
    "type": "virtualbox-windows-iso",
    "guest_os_type": "Windows2008_64",
    "disk_size": 21440,
    "iso_url": "D:/ISOs/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso",
    "iso_checksum": "4263be2cf3c59177c45085c0a7bc6ca5",
    "iso_checksum_type": "md5",
    "boot_wait": "2m",
    "winrm_username": "vagrant",
    "winrm_password": "vagrant",
    "winrm_wait_timeout": "10m",
    "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
    "vboxmanage": [
      ["modifyvm", "{{.Name}}", "--memory", "2048"],
      ["modifyvm", "{{.Name}}", "--cpus", "2"]
    ],
    "floppy_files": [
      "./answer_files/windows-2008r2-standard/Autounattend.xml"
    ]
  }],
  "provisioners": [
    {
      "type": "powershell",
      "inline": "$PSVersionTable"
    }
  ]
}

And here is the full output from the build:

PS D:\packer> packer build .\windows-virtualbox.json
virtualbox-windows-iso output will be in this color.

==> virtualbox-windows-iso: Downloading or copying Guest additions
    virtualbox-windows-iso: Downloading or copying: file:///C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
==> virtualbox-windows-iso: Downloading or copying ISO
    virtualbox-windows-iso: Downloading or copying: file:///D:/ISOs/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMS
XEVAL_EN_DVD.iso
==> virtualbox-windows-iso: Creating floppy disk...
    virtualbox-windows-iso: Copying: ./answer_files/windows-2008r2-standard/Autounattend.xml
==> virtualbox-windows-iso: Creating virtual machine...
==> virtualbox-windows-iso: Creating hard drive...
==> virtualbox-windows-iso: Attaching floppy disk...
==> virtualbox-windows-iso: Creating forwarded port mapping for WinRM (host port 6849)
==> virtualbox-windows-iso: Executing custom VBoxManage commands...
    virtualbox-windows-iso: Executing: modifyvm packer-virtualbox-windows-iso-1422934196 --memory 2048
    virtualbox-windows-iso: Executing: modifyvm packer-virtualbox-windows-iso-1422934196 --cpus 2
==> virtualbox-windows-iso: Starting the virtual machine...
==> virtualbox-windows-iso: Waiting 2m0s for boot...
==> virtualbox-windows-iso: Typing the boot command...
==> virtualbox-windows-iso: Waiting for WinRM to become available...
==> virtualbox-windows-iso: Connected to WinRM!
==> virtualbox-windows-iso: Uploading VirtualBox version info (4.3.20)
==> virtualbox-windows-iso: Uploading VirtualBox guest additions ISO...
==> virtualbox-windows-iso: Provisioning with Powershell...
==> virtualbox-windows-iso: Unable to extract inline scripts into a file: open \tmp\packer-powershell-provisioner1992244
47: The system cannot find the path specified.
==> virtualbox-windows-iso: Provisioning with shell script:
==> virtualbox-windows-iso: Unregistering and deleting virtual machine...
==> virtualbox-windows-iso: Deleting output directory...
Build 'virtualbox-windows-iso' errored: Error opening shell script: open : The system cannot find the file specified.

==> Some builds didn't complete successfully and had errors:
--> virtualbox-windows-iso: Error opening shell script: open : The system cannot find the file specified.

==> Builds finished but no artifacts were created.
mefellows commented 9 years ago

Ah yes of course. Sorry I haven't the code in front me but this makes sense. I'll see about testing on a Windows machine then.

mefellows commented 9 years ago

Thanks @zl4bv, this works nicely.