Maybe I'm missing something obvious here, but if a different Vagrant repository is used with the builder, the generated Vagrantfile does not work. In my case, JFrog's Artifactory is used to host a local box repository.
To resolve a box, a URL with the following format: https://{Artifactory URL}/api/vagrant/{vagrantRepoKey}/{boxName} is used and resolves to the latest version. The box is added correctly by packer. However, the created Vagrantfile looks as follows:
Vagrant.configure("2") do |config|
config.vm.define "source", autostart: false do |source|
source.vm.box = "https://<local_adress>/artifactory/api/vagrant/vagrant-repo/debian-12.5"
config.ssh.insert_key = false
end
config.vm.define "output" do |output|
output.vm.box = "debian-12.5"
output.vm.box_url = "file://package.box"
config.ssh.insert_key = false
end
config.vm.synced_folder ".", "/vagrant", disabled: true
end
This results in the following error messages:
The box you're adding has a name different from the name you
2024/03/20 10:50:52 packer-plugin-vagrant_v1.1.1_x5.0_linux_amd64 plugin: 2024/03/20 10:50:52 [vagrant driver] stderr: requested. For boxes with metadata, you cannot override the name.
2024/03/20 10:50:52 packer-plugin-vagrant_v1.1.1_x5.0_linux_amd64 plugin: 2024/03/20 10:50:52 [vagrant driver] stderr: If you're adding a box using `vagrant box add`, don't specify
2024/03/20 10:50:52 packer-plugin-vagrant_v1.1.1_x5.0_linux_amd64 plugin: 2024/03/20 10:50:52 [vagrant driver] stderr: the `--name` parameter. If the box is being added via a Vagrantfile,
2024/03/20 10:50:52 packer-plugin-vagrant_v1.1.1_x5.0_linux_amd64 plugin: 2024/03/20 10:50:52 [vagrant driver] stderr: change the `config.vm.box` value to match the name below.
2024/03/20 10:50:52 packer-plugin-vagrant_v1.1.1_x5.0_linux_amd64 plugin: 2024/03/20 10:50:52 [vagrant driver] stderr:
2024/03/20 10:50:52 packer-plugin-vagrant_v1.1.1_x5.0_linux_amd64 plugin: 2024/03/20 10:50:52 [vagrant driver] stderr: Requested name: https://<local_adress>/artifactory/api/vagrant/vagrant-repo/debian-12.5
2024/03/20 10:50:52 packer-plugin-vagrant_v1.1.1_x5.0_linux_amd64 plugin: 2024/03/20 10:50:52 [vagrant driver] stderr: Actual name: debian-12.5
Considering how the Vagrantfile is created, source.vm.box = "{{.BoxName}}" would resolve this issue and allows a correct run.
As a temporary workaround I provided an adjusted template:
Vagrant.configure("2") do |config|
config.vm.define "source", autostart: false do |source|
source.vm.box = "{{.BoxName}}"
config.ssh.insert_key = {{.InsertKey}}
end
config.vm.define "output" do |output|
output.vm.box = "{{.BoxName}}"
output.vm.box_url = "file://package.box"
config.ssh.insert_key = {{.InsertKey}}
end
{{ if ne .SyncedFolder "" -}}
config.vm.synced_folder "{{.SyncedFolder}}", "/vagrant"
{{- else -}}
config.vm.synced_folder ".", "/vagrant", disabled: true
{{- end}}
end
Reproduction Steps
Setup a local vagrant repository
Add a box
Use the Buildfile provided below
Run packer with PACKER_LOG=10 packer build --debug . to see the appropriate error messages.
Overview of the Issue
Maybe I'm missing something obvious here, but if a different Vagrant repository is used with the builder, the generated Vagrantfile does not work. In my case, JFrog's Artifactory is used to host a local box repository. To resolve a box, a URL with the following format:
https://{Artifactory URL}/api/vagrant/{vagrantRepoKey}/{boxName}
is used and resolves to the latest version. The box is added correctly by packer. However, the created Vagrantfile looks as follows:This results in the following error messages:
Considering how the Vagrantfile is created,
source.vm.box = "{{.BoxName}}"
would resolve this issue and allows a correct run. As a temporary workaround I provided an adjusted template:Reproduction Steps
PACKER_LOG=10 packer build --debug .
to see the appropriate error messages.Plugin and Packer version
Packer v1.9.4 Plugin: v1.1.1_x5.0_linux_amd64
Simplified Packer Buildfile