Search code examples
vagrantvagrantfilevagrant-plugin

Can I - vagrant add box - inside a Vagrantfile?


If I understood correctly, the intention with using vagrant is to have a workflow in which the developer pulls the project sources along with the Vagrantfile, runs "vagrant up" and that's it right? The developer is not suppose to list and add boxes right, he shouldn't care about devops... that's the intention, to create as little friction as possible before a developer will be up and running, and let him/her focus on the app they're building... so? can I include in the Vagrant file adding boxes? only if they are not available? hey - what about vagrant plugins? can I add those to the Vagrantfile too? Is Vagrant smart enough not to run unnecessary provisioning twice? cheers, Ajar


Solution

    1. You can instruct in your Vagrant file which base box should be used as the starting point. If this box is not found on the host, Vagrant will try to download it from Atlas (Vagrant's box repository) or from custom link if provided. Read about config.vm.box and config.vm.box_url config options.

    2. No, Vagrant plugins need to be installed manually from command line. You can add check in Vagrantfile to see if plugin is installed or not. See this answer for more info.

    3. Vagrant will run provision only once when VM is created. You can re-run provision if needed from command line, but Vagrant doesn't know anything about what your provision is doing. It's just executing it. If you use solutions such as Puppet/Chef/Ansible to run provision, they are "smart enough" not to repeat the same provision steps if the desired state was achieved.