Skip to content

Packer option -var-file=path interpretated with double backslashe #12726

@spawn451

Description

@spawn451

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

Overview of the Issue

I'm trying to run Packer from a Powershell script. I use the -var-file=path option to specify the path of my HCL configuration files.
This does not work, Packer can't read the files because the specified paths are always interpreted with double backslashes.

Reproduction Steps

Sample of my powershell script :

# Run Packer
$CONFIG_PATH = (Get-Item .).FullName
$VSPHERE_FILE = "$CONFIG_PATH\vsphere.pkrvars.hcl"
$VAULT_FILE = "$CONFIG_PATH\vault.pkr.hcl"
$COMMON_FILE = "$CONFIG_PATH\common.pkrvars.hcl"
$SCRIPT_PATH = (Get-Item .).FullName
$INPUT_PATH = "$SCRIPT_PATH\builds\windows\server\2022\"

packer init $INPUT_PATH

packer build -force -only vsphere-iso.windows-server-standard-dexp,vsphere-iso.windows-server-standard-core -var-file="$VSPHERE_FILE" -var-file="$VAULT_FILE" -var-file="$COMMON_FILE" "$INPUT_PATH"

Output :

PS D:\_DevOps\_Packer\templates-vmware_v2> D:\_DevOps\_Packer\templates-vmware_v2\build.ps1
Error: Failed to read file

The configuration file
"D:\\_DevOps\\_Packer\\templates-vmware_v2\\vsphere.pkrvars.hcl" could not be
read.

Error: Failed to read file

The configuration file
"D:\\_DevOps\\_Packer\\templates-vmware_v2\\vault.pkr.hcl" could not be read.

Error: Failed to read file

The configuration file
"D:\\_DevOps\\_Packer\\templates-vmware_v2\\common.pkrvars.hcl" could not be
read.

Packer version

From 1.9.4

Operating system and Environment details

Windows 10 22H2

Log Fragments and crash.log files

log detail. PS D:\_DevOps\_Packer\templates-vmware_v2> D:\_DevOps\_Packer\templates-vmware_v2\build.ps1 packer : 2023/11/30 11:43:17 [INFO] Packer version: 1.9.4 [go1.20.7 windows amd64] Au caractère D:\_DevOps\_Packer\templates-vmware_v2\build.ps1:47 : 1 + packer init $INPUT_PATH + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (2023/11/30 11:4... windows amd64]:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError

2023/11/30 11:43:17 [TRACE] discovering plugins in C:\Program Files\HashiCorp
2023/11/30 11:43:17 [TRACE] discovering plugins in .
2023/11/30 11:43:17 [TRACE] discovering plugins in C:\Users\DJE\AppData\Roaming\packer.d\plugins
2023/11/30 11:43:17 [INFO] Discovered potential plugin: ansible = C:\Users\DJE\AppData\Roaming\packer.d\plugins\github.com\hashicorp\ansible\packer-plugin-ansible_v1.1.1_x5.0_windows_amd64.exe
2023/11/30 11:43:17 [INFO] Discovered potential plugin: vsphere = C:\Users\DJE\AppData\Roaming\packer.d\plugins\github.com\hashicorp\vsphere\packer-plugin-vsphere_v1.2.2_x5.0_windows_amd64.exe
2023/11/30 11:43:17 [INFO] Discovered potential plugin: windows-update = C:\Users\DJE\AppData\Roaming\packer.d\plugins\github.com\rgl\windows-update\packer-plugin-windows-update_v0.14.3_x5.0_windows_amd64.exe
2023/11/30 11:43:17 found external [-packer-default-plugin-name- local] provisioner from ansible plugin
2023/11/30 11:43:18 [INFO] found external [clone iso supervisor] builders from vsphere plugin
2023/11/30 11:43:18 [INFO] found external [-packer-default-plugin-name- template] post-processors from vsphere plugin
2023/11/30 11:43:18 found external [-packer-default-plugin-name-] provisioner from windows-update plugin
2023/11/30 11:43:18 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2023/11/30 11:43:18 [INFO] PACKER_CONFIG env var set; attempting to open config file: C:\Users\DJE\AppData\Roaming\packer.config
2023/11/30 11:43:18 [WARN] Config file doesn't exist: C:\Users\DJE\AppData\Roaming\packer.config
2023/11/30 11:43:18 [INFO] Setting cache directory: D:_DevOps_Packer\templates-vmware_v2\packer_cache
e: cannot determine if process is in background: Process background check error: not implemented yet
2023/11/30 11:43:18 [TRACE] init: plugingetter.ListInstallationsOptions{FromFolders:[]string{"C:\Program Files\HashiCorp", ".", "C:\Users\DJE\AppData\Roaming\packer.d\plugins"},
BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"windows", ARCH:"amd64", Ext:".exe", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256",
Hash:(*sha256.digest)(0xc0004ea480)}}}}
2023/11/30 11:43:18 [TRACE] listing potential installations for "github.com/hashicorp/vsphere" that match ">= 1.2.1". plugingetter.ListInstallationsOptions{FromFolders:[]string{"C:\Program Files\HashiCorp", ".",
"C:\Users\DJE\AppData\Roaming\packer.d\plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"windows", ARCH:"amd64", Ext:".exe",
Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc0004ea480)}}}}
2023/11/30 11:43:18 [TRACE] for plugin github.com/hashicorp/vsphere found 1 matching installation(s)
2023/11/30 11:43:18 [TRACE] listing potential installations for "github.com/rgl/windows-update" that match ">= 0.14.3". plugingetter.ListInstallationsOptions{FromFolders:[]string{"C:\Program Files\HashiCorp", ".",
"C:\Users\DJE\AppData\Roaming\packer.d\plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"windows", ARCH:"amd64", Ext:".exe",
Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc0004ea480)}}}}
2023/11/30 11:43:18 [TRACE] for plugin github.com/rgl/windows-update found 1 matching installation(s)
2023/11/30 11:43:18 [INFO] (telemetry) Finalizing.
2023/11/30 11:43:18 waiting for all plugin processes to complete...
packer : 2023/11/30 11:43:19 [INFO] Packer version: 1.9.4 [go1.20.7 windows amd64]
Au caractère D:_DevOps_Packer\templates-vmware_v2\build.ps1:49 : 1

  • packer build -force -only vsphere-iso.windows-server-standard-dexp,vs ...
  •   + CategoryInfo          : NotSpecified: (2023/11/30 11:4... windows amd64]:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

2023/11/30 11:43:19 [TRACE] discovering plugins in C:\Program Files\HashiCorp
2023/11/30 11:43:19 [TRACE] discovering plugins in .
2023/11/30 11:43:19 [TRACE] discovering plugins in C:\Users\DJE\AppData\Roaming\packer.d\plugins
2023/11/30 11:43:19 [INFO] Discovered potential plugin: ansible = C:\Users\DJE\AppData\Roaming\packer.d\plugins\github.com\hashicorp\ansible\packer-plugin-ansible_v1.1.1_x5.0_windows_amd64.exe
2023/11/30 11:43:19 [INFO] Discovered potential plugin: vsphere = C:\Users\DJE\AppData\Roaming\packer.d\plugins\github.com\hashicorp\vsphere\packer-plugin-vsphere_v1.2.2_x5.0_windows_amd64.exe
2023/11/30 11:43:19 [INFO] Discovered potential plugin: windows-update = C:\Users\DJE\AppData\Roaming\packer.d\plugins\github.com\rgl\windows-update\packer-plugin-windows-update_v0.14.3_x5.0_windows_amd64.exe
2023/11/30 11:43:19 [INFO] found external [clone iso supervisor] builders from vsphere plugin
2023/11/30 11:43:19 [INFO] found external [-packer-default-plugin-name- template] post-processors from vsphere plugin
2023/11/30 11:43:19 found external [-packer-default-plugin-name-] provisioner from windows-update plugin
2023/11/30 11:43:19 found external [-packer-default-plugin-name- local] provisioner from ansible plugin
2023/11/30 11:43:19 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2023/11/30 11:43:19 [INFO] PACKER_CONFIG env var set; attempting to open config file: C:\Users\DJE\AppData\Roaming\packer.config
2023/11/30 11:43:19 [WARN] Config file doesn't exist: C:\Users\DJE\AppData\Roaming\packer.config
2023/11/30 11:43:19 [INFO] Setting cache directory: D:_DevOps_Packer\templates-vmware_v2\packer_cache
e: cannot determine if process is in background: Process background check error: not implemented yet
The configuration file
"D:\_DevOps\_Packer\templates-vmware_v2\vsphere.pkrvars.hcl" could not be
read.
Error: Failed to read file
Error: Failed to read file
The configuration file
"D:\_DevOps\_Packer\templates-vmware_v2\vault.pkr.hcl" could not be read.
Error: Failed to read file

The configuration file
"D:\_DevOps\_Packer\templates-vmware_v2\common.pkrvars.hcl" could not be
read.
2023/11/30 11:43:19 [INFO] (telemetry) Finalizing.
The configuration file
"D:\_DevOps\_Packer\templates-vmware_v2\vsphere.pkrvars.hcl" could not be
read.

Error: Failed to read file

The configuration file
"D:\_DevOps\_Packer\templates-vmware_v2\vault.pkr.hcl" could not be read.

Error: Failed to read file

The configuration file
"D:\_DevOps\_Packer\templates-vmware_v2\common.pkrvars.hcl" could not be
read.

2023/11/30 11:43:19 waiting for all plugin processes to complete...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions