3

I would like to pass ISO_URL as a command line parameter. I tried to follow an example at https://www.packer.io/docs/templates/user-variables.html

Where my variable section looks like

"variables": {
    "build_version": "1.0.0",
    "iso_checksum_type":"md5", 
    "iso_checksum":"453312bf56fc45669fec5ebc0f025ac7",
    "iso_url":"c:\fake.iso"
}

the variable references

   ...
  "iso_checksum": "{{user `iso_checksum`}}",
  "iso_checksum_type":"{{user `iso_checksum_type`}}",
  "iso_url": "{{user `iso_url`}}",
  ...

and the build command is

packer build -var 'iso_url=c:\debian.iso' packerio.json

However, the iso_url is not overwritten and packer is trying to download the fake.iso

Why?

The exact result is

virtualbox-iso output will be in this color.

==> virtualbox-iso: Downloading or copying Guest additions
virtualbox-iso: Downloading or copying: file:///C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
==> virtualbox-iso: Downloading or copying ISO
virtualbox-iso: Downloading or copying: file:///c:/fake.iso
virtualbox-iso: Error downloading: GetFileAttributesEx c:/fake.iso: The system cannot find the file specified.
==> virtualbox-iso: ISO download failed.
Build 'virtualbox-iso' errored: ISO download failed.

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: ISO download failed.

==> Builds finished but no artifacts were created.
Roman Mik
  • 3,179
  • 3
  • 27
  • 49
  • Could you add the part of your template where you are referencing the _user variable_ `iso_url`? – Rickard von Essen Jan 26 '17 at 07:52
  • @RickardvonEssen I edited the question with that section – Roman Mik Jan 26 '17 at 14:24
  • That looks correct. The only other thing I could think about is how you quote command line arguments with single quotes on Windows. I know nothing about Windows but it's probably worth exploring if the problem is there. What happens if you remove the quotes? – Rickard von Essen Jan 26 '17 at 15:36
  • Thank you @RickardvonEssen, you were right it is the windows issue. double quotes is the way to go. – Roman Mik Jan 26 '17 at 15:49

1 Answers1

5

The solution is to replace the single quote with double or leave the quotes out.

packer build -var "iso_url=c:\debian.iso" packerio.json

or

packer build -var iso_url=c:\debian.iso packerio.json

Also, relative path works too

packer build -var iso_url=\subfolder_name\debian.iso packerio.json

Thank you @RickardvonEssen for pointing me in the right direction.

Roman Mik
  • 3,179
  • 3
  • 27
  • 49