I just started using Vagrant. Now, One of my clients shared a GIT repo with the following files & directories :
Vagrantfile (file)
Vagrant (directory)
Now, I don't understand what will be my next step ? Every resource in the internet assumes that I am creating a new box from scratch (vagrant init hashicorp/precise64). But, here I need to match the box environment that is shared with me.
Thanks.
As stated in the previous answers - download the repository, and enter (cd via command line) the directory.
Once in there - you should just be able to run vagrant up to initiate the download and configuration of the vagrant box. Your client will (in theory) have set up the Vagrantfile to configure the machine appropriately.
Note: It might be worth checking to see if they have specified a hostname for the box [i.e mynewproject.dev] (found in Vagrantfile or sometimes, in a .yaml configuration file (i.e site.yaml).
If they have - it would be worth updating your hosts file to make sure you can use the host name locally.
The Vagrantfile will described everything about the VM you will build, so it knows about the vagrant box to use, you will have something like
Vagrant.configure("2") do
....
config.box = "hashicorp/precise64"
...
end
If the box is available freely on Atlas (such as hashicorp/precise64) vagrant will download the box and spin a new VM. If the box is not freely available, you will need to install yourself with vagrant box add
Related
I've uploaded a Vagrant box to Vagrant Cloud. My box has some custom config, so I want to customize the Vagrantfile that is created with vagrant init. The Vagrant documentation hasn't been much help.
I'm working around this by distributing the correct Vagrantfile, but I'd prefer for users to just init the box and get my custom Vagrantfile. Is this even possible?
You can package a Vagrantfile along with your box.
you can look at some common box like ubuntu/trusty64 or ubuntu/xenial64 which comes with their own Vagrantfile (you can review the Vagrantfile under the ~/.vagrant.d/boxes/<name>/<version>/<provider>/Vagrantfile
You can read about Vagrantfile load order and merging : vagrant reads the Vagrantfile from the box at first and those params can be overridden by the main Vagrantfile from the project directory
In the old days, you would use the vagrant package command and there's still some good doc on https://www.vagrantup.com/docs/cli/package.html
A common misconception is that the --vagrantfile option will package a
Vagrantfile that is used when vagrant init is used with this box. This
is not the case. Instead, a Vagrantfile is loaded and read as part of
the Vagrant load process when the box is used. For more information,
read about the Vagrantfile load order.
I currently have multiple dev sites that each use Vagrant and scotchbox. Each site directory has its own copy of scotchbox, but since they're all the same I'd like to have just one scotchbox VM that I can start with any Vagrantfile, where each Vagrantfile would just change the config.vm.synced_folder.
So, for example, let's say I have:
~/Sites/cheese/
~/Sites/bacon/
~/Sites/eggs/
and then
~/Sites/sctoch-box
I'd like to be able to startup and shutdown Vagrant from ~/Sites/cheese/ or ~/Sites/bacon/ and so on without each also having their own copy of scotch-box.
Is that possible?
Yes you could potentially do that - I've not tested and don't think its official supported
but you can create the first VM from your Vagrantfile within the ~/Sites/cheese/ project, once you have created the VM, copy the Vagrant file and .vagrant directory from ~/Sites/cheese/ into ~/Sites/bacon/ and ~/Sites/egges/ so all will point to the same VM. Edit your Vagrantfile within each of your project to change the Vagrantfile if needed.
You will be able to start the VM from any of this project, but as its single VM, if you try to run vagrant from another project directory, it will not work.
I was using a computer with an already configured Vagrant/VirtualBox ambient. Now, I need to put this box in another computer.
So, I do the vagrant package and added the box in my new computer.
So when I go vagrant up and vagrant ssh everything looks perfect, and all my files are there.
But when I try to access my localhost, vagrant just show me "It Works" page.
I guess I'm missing some reference or link to my project or something like that.
I'm using Ubuntu in both computers and my project use FuelPhp.
You have some options here.
First Option
Use a synced folder in your Vagrantfile
e.g
config.vm.synced_folder ".", "/var/www"
This will change your share folder mount in /vagrant/educarebr to /var/www and Apache will see the folder.
Second Option
Create a symbolic link in vagrant using a provisioner, as Shell Script.
Third Option
Create a new virtual host in your Apache with DocumentRoot /vagrant/educarebr.
However, check your old Vagrantfile and compare with your new Vagrantfile that you are using with box created with vagrant package.
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
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.
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.
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.
I had a dev setup the vagrant box and he uploaded the file which I now have on my local machine. But I am not sure how to use it as I never used vagrant before. Can someone help with the docs or directions.
thanks
Full documentation for Vagrant can be found on the website. From a practical point of view, a Vagrant box is just a provisioned VirtualBox VM.
If someone else gave you the box, they can show you how to log into it as well. After that, get coding!
Having the box file is one of the steps to have a proper development environment configured. You also need to have the configuration file vagrantfile.
Vagrant is meant to run with one Vagrantfile per project. For example; if your project path is located at C:\vagrant\project01\, inside that folder you need to put the vagrantfile related to that box. Remember this file should contain the configuration for the box that you previously downloaded.
In the case that you don’t have this file but want to use the box to adapt it to you needs you can also can configure Vagrant for that. You just need to go to the cmd, and cd (got to directory) folder of the project, in this case C:\vagrant\project01\. In the cmd windows type vagrant init and Vagrant will generate a vagrantfile for this project. In that file you can modify the config.vm.box_url parameter to point to your current box. This address could be a URI or the path to the box in your host machine for example “c:\virtualmachines\devel\machineboxname.box”.
Vagrant is so powerful that we have done no more than skim the surface of these topics.
If you just want to re-package a .box file that you were given, then you can try "vagrant box add " where the address is a URL or a physical address. Once that box is added, you can call "vagrant init" to generate your Vagrantfile and "vagrant up" to make a virtual machine based on your friend's base box. The folder that you're currently in then becomes the place where you do all future vagrant commands for this virtual machine.