hashicorp / hashicorp/packer-plugin-vagrant

vagrant builder's vagrantfile template mixes source and output

Open
#7 0 comments 0 reactions 0 assignees View on GitHub
bug builder/vagrant
Dominant language
Go
Stars
16
Forks
28
PR merge metrics
No merged PRs in 30d

Description

_This issue was originally opened by @andkononykhin as hashicorp/packer#8245. It was migrated here as a result of the [Packer plugin split](https://github.com/hashicorp/packer/issues/8610#issuecomment-770034737). The original body of the issue is below._


#### Overview of the Issue

A patch hashicorp/packer#7957 introduced new multi-machine vagrantfile template for vagrant builder:
- source box is taken by `source_path` but not by `box_name`
- for output machine it sets box name of the source box as a `vm.box` but also sets output package.box file as `vm.box_url` which seems confusing

It leads to:
- `vagrant up` itself during packer build tries to add box for source machine and it might fail the build if the source path is too long
- two boxes are actually added during the build: one by packer with `box_name` value and one by vagrant with `source_path` value as a name
- `vagrant up output` will bring up machine based on a source box instead of output one

### Packer version

1.4.4

### Simplified Packer Buildfile

```
{
"builders": [
{
"type" : "vagrant",
"provider" : "virtualbox",
"source_path" : "{{template_dir}}/../../bla/bla/bla/long-path/package.box",
"add_force" : true,
"box_name" : "centos7-base",
"output_dir" : "{{template_dir}}/../../.boxes/centos7-with-new-dir",
"communicator" : "ssh",
...
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"mkdir -p /tmp/new"
]
}
]
}
```
### Generated Vagrantfile

```
Vagrant.configure("2") do |config|
config.vm.define "source", autostart: false do |source|
source.vm.box = "... .../../../bla/bla/bla/long-path/package.box"
end
config.vm.define "output" do |output|
output.vm.box = "centos7-base"
output.vm.box_url = "file://package.box"
end
config.vm.synced_folder ".", "/vagrant", disabled: true
end
```

### Operating system and Environment details

centos7

### Log Fragments and crash.log files

```
2019/10/18 14:46:51 packer: 2019/10/18 14:46:51 Calling Vagrant CLI: []string{"up", "source", "--provider=virtualbox"}
2019/10/18 14:46:55 packer: 2019/10/18 14:46:55 [vagrant driver] stdout: Bringing machine 'source' up with 'virtualbox' provider...
2019/10/18 14:46:55 packer: ==> source: Box '... .../../../bla/bla/bla/long-path/package.box' could not be found. Attempting to find and install...
2019/10/18 14:46:55 packer: source: Box Provider: virtualbox
2019/10/18 14:46:55 packer: source: Box Version: >= 0
2019/10/18 14:46:55 packer: ==> source: Box file was not detected as metadata. Adding it directly...
2019/10/18 14:46:55 packer: ==> source: Adding box '... .../../../bla/bla/bla/long-path/package.box' (v0) for provider: virtualbox
2019/10/18 14:46:55 packer: source: Unpacking necessary files from: file://... .../../../bla/bla/bla/long-path/package.box

2019/10/18 14:46:55 packer: 2019/10/18 14:46:55 [vagrant driver] stderr: /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/fileutils.rb:230:in `mkdir': File name too long @ dir_s_mkdir - ... ...-VAGRANTSLASH-..-VAGRANTSLASH-..-VAGRANTSLASH-bla-VAGRANTSLASH-bla-VAGRANTSLASH-bla-VAGRANTSLASH-long-path-VAGRANTSLASH-package.box (Errno::ENAMETOOLONG)
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/fileutils.rb:230:in `fu_mkdir'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/fileutils.rb:208:in `block (2 levels) in mkdir_p'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/fileutils.rb:206:in `reverse_each'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/fileutils.rb:206:in `block in mkdir_p'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/fileutils.rb:191:in `each'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/fileutils.rb:191:in `mkdir_p'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/pathname.rb:576:in `mkpath'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:161:in `block (3 levels) in add'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:470:in `with_temp_dir'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:134:in `block (2 levels) in add'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:470:in `with_temp_dir'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:115:in `block in add'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:457:in `block in with_collection_lock'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:456:in `with_collection_lock'
2019/10/18 14:46:55 packer: from /tmp/.mount_vagran5Uh4mU/usr/gembundle/gems/vagrant-2.2.5/lib/vagrant/box_collection.rb:104:in `add'
==> vagrant: destroying Vagrant box...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.