config.vm.synced_folder ignored in default Vagrantfile

67 views
Skip to first unread message

Krist van Besien

unread,
Jul 7, 2017, 11:44:31 AM7/7/17
to Vagrant
Hello all,

I created my own box, and the box, and the Vagrantfile included in the box has the following content:

Vagrant.configure("2") do |config|
        config
.vm.provider :libvirt do |libvirt|
          libvirt
.disk_bus = 'virtio'
       
end
        config
.vm.synced_folder  ".", "/vagrant", disabled: true
end


However this setting is ignored. After doing a "vagrant init <mybox>" I need to edit the Vagrantfile manually to again disable the synced folder.

Why is that?






Jamie Jackson

unread,
Jul 7, 2017, 12:24:50 PM7/7/17
to vagra...@googlegroups.com
If I understand the question correctly, you're saying you've built a box and now you're trying to use it.

When you `vagrant init` you're creating a generic Vagrantfile, but it will have the config.vm.box value set to the box you inited with. When you `vagrant up` with that Vagrantfile, Vagrant will create that vagrant synced folder. If you don't want that in your running VM, you'll need to add that disabling line to the Vagrantfile. This also means that the Vagrantfile that you run your box with is important, and you'll want to keep it (e.g., in SCM), so don't `vagrant init` on top of it.

I might be assuming too much, but have you worked with any public boxes yet? If not, it might be confusing to try to grok box creation and box consumption all at once. It's probably easier to work with a public box and do a little provisioning (in Vagrantfile) to see how that part works before building your own boxes.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/317ab26a-7323-4b15-98a7-69d97a6d11bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Salty Vagrant

unread,
Jul 7, 2017, 12:47:38 PM7/7/17
to Vagrant

I suspect this is simply a misunderstanding of the vagrant commands.

Once you have your edited Vagrantfile (with the synced_folder disabled) you should use ‘vagrant up’ NOT ‘vagrant init’.

‘vagrant init’ creates a new Vagrantfile and sets the vm/box to the value you provide on the command line (this will overwrite the one you previously created).

‘vagrant up’ on the other hand will start the VM specified by the Vagrantfile.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.

Krist van Besien

unread,
Jul 12, 2017, 5:47:18 AM7/12/17
to Vagrant
I've been using Vagrant extensively. So I know the difference between init and up.

My problem is the following:

- I created a box myself, by packaging an image, together with a Vagrantfile and a Metadata.json file.
- In that Vagrantfile I have the following content:


Vagrant.configure("2") do |config|
        config
.vm.provider :libvirt do |libvirt|
          libvirt
.disk_bus = 'virtio'
       
end
        config
.vm.synced_folder  ".", "/vagrant", disabled: true
end

So I tarred/ziped those three files in to a new box, and imported that in to Vagrant.

Then I tested this. I created a new directory, and in that directory I did:

vagrant init newbox
vagrant up

What I expected to happen:

The box is started, but no synced folder is setup.

What I got:

Box is started, and vagrant attempts to setup a synced folder, which fails on this particular image. (and this is why I want it to be disabled by default)

In other words, I expect (and the documentation has led me to expect this) that the config you put in the Vagrantfile you package in a box is interpreted as a default for that box, and that this config is merged with the Vagrantfile created by vagrant init in your working directory. In other words, I expect to be able to set defaults in a box.

Are my expectations incorrect? Or did I do something wrong? Or is this a bug?

Alvaro Miranda Aguilera

unread,
Jul 17, 2017, 4:20:32 AM7/17/17
to vagra...@googlegroups.com
hello

can you check the file is there once untarred by Vagrant?

find ~/.vagrant.d/boxes

if you add

puts __FILE__

it should print the name of the file when you run any command, ie vagrant status

this is helpful to confirm is being loaded.

if thats the case, then could you open an issue on github?

Thanks
Alvaro

To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/5345e486-c18f-4d34-93a3-62b03e557dad%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages