Packer 在文件存在时找不到文件

Packer cannot find file when it is there

我正在尝试从我的主目录 C:\Users[User]\ 运行 packer validate ./Vagrant/windows_7.json,但它在脚本部分失败并出现错误 The system cannot find the path specified。我可以使用 Fully Qualified 路径,它工作正常,但由于某种原因它对 relative 不起作用。配置中是否有任何内容表明系统找不到该文件的原因?这很奇怪,因为它可以很容易地找到 ./iso/Windows_7.iso,但找不到 vagrantfile-windows_7.template 和脚本。 packer 目录查看与 .json 构建文件相关的所有内容,对吗?我也试过检查权限,但我的用户名具有完全访问权限。我还有 Windows.

的最新 Packer 0.10.1
{
  "builders": [
    {
      "type": "virtualbox-iso",
      "iso_url": "{{user `iso_url`}}",
      "iso_checksum_type": "{{user `iso_checksum_type`}}",
      "iso_checksum": "{{user `iso_checksum`}}",
      "headless": true,
      "boot_wait": "2m",
      "ssh_username": "vagrant",
      "ssh_password": "vagrant",
      "ssh_wait_timeout": "8h",
      "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
      "guest_os_type": "Windows7_64",
      "disk_size": 61440,
      "floppy_files": [
        "{{user `autounattend`}}",
        "./scripts/dis-updates.ps1",
        "./scripts/hotfix-KB3102810.bat",
        "./scripts/microsoft-updates.bat",
        "./scripts/win-updates.ps1",
        "./scripts/openssh.ps1",
        "./scripts/oracle-cert.cer"
      ],
      "vboxmanage": [
        [
          "modifyvm",
          "{{.Name}}",
          "--memory",
          "2048"
        ],
        [
          "modifyvm",
          "{{.Name}}",
          "--cpus",
          "2"
        ]
      ]
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "remote_path": "/tmp/script.bat",
      "execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
      "scripts": [
        "./scripts/vm-guest-tools.bat",
        "./scripts/vagrant-ssh.bat",
        "./scripts/disable-auto-logon.bat",
        "./scripts/enable-rdp.bat",
        "./scripts/compile-dotnet-assemblies.bat",
        "./scripts/compact.bat"
      ]
    }
  ],
  "post-processors": [
    {
      "type": "vagrant",
      "keep_input_artifact": false,
      "output": "windows_7_{{.Provider}}.box",
      "vagrantfile_template": "vagrantfile-windows_7.template"
    }
  ],
  "variables": {
    "iso_url": "./iso/Windows_7.iso",
    "iso_checksum_type": "SHA1",
    "iso_checksum": "36AE90DEFBAD9D9539E649B193AE573B77A71C83",
    "autounattend": "./answer_files/Autounattend.xml"
  }
}

当 运行 加壳器构建 json 模板时,我遇到了同样的问题,因为它使用的是当前目录而不是 json 模板目录

C:...>cd Vagrant
C:...\Vagrant> packer validate windows_7.json

在您的模板中,您引用了脚本 ./scripts/dis-updates.ps1 并且该脚本位于 C:/.../Vagrant/scripts/dis-updates.ps1 下,但是当加壳器验证您的模板时,它采用您的当前目录而不是模板所在的目录。