Export customized vagrant - clone

I mounted a vagrant machine several time ago.I have modified some configurations to the VM since the installation and now my co-workers need to use exactly the same VM.
How can I do it ? I would like keep the database i used for my co-workers too if it's possible.

Look into VagrantCloud: https://vagrantcloud.com/
I'm using that service to host a customized box for my team. Started from a vanilla box, customized it to match our environment, then used the "vagrant package" command to create a new *.box file. You just need to host that file somewhere online, register it with the VagrantCloud service, and you can manage box releases and deployments for your co-workers. It even notifies them if you update the box. Pretty nifty.
As far as the DB, if it is in the VM it will get packaged up too. Might wat to look into providing updated DB files for later since they will get out of date fast, I would imagine.

Related

is Vagrant suitable for beginners that are not tech savvy?

I'm planning to teach a group a people how to setup a website using WordPress. Those people have some basic computer usage knowledge : they can surf the web, write emails, install software on their computer, ... But they are absolutely not developers. And the training does not aim to teach them development.
But I want them to be able to setup a fully working local web environment or their computer that runs on Windows. I was planning to use XAMPP, but I'm wondering if Vagrant is not more suitable. I could prepare a box with a lot of tools already included, and they will just have to install it. Interaction with the server would take place only via http and FTP (no ssh needed).
Is it possible to create a batch file that they can click on to launch the Vagrant ? If properly configured, is that as easy to use as that for absolute beginners ?
from what you describe there is almost no vagrant thing, you would be responsible to make the vagrant box and the vagrantfile, and you will not expose your students to vagrant. only thing is that they would need to have this bat file on their desktop (the only command that it will need to run is vagrant up, make sure to expose the vagrant cwd variable) and the server will be up and running.
The main advantage I see then is that you will completely make your students in the same situation they will be with their production system. they will face the same tool (FTP, wordpress admin ...) on an environment (more or less) identical to a production environment.

Is Vagrant Provision suppose to wipe out all your data

I just ran vagrant provision in a futile attempt at getting my customized synced_folders directive to work and now my whole guest box is wiped out.
Is this normal? I don't see any references to Vagrant docs about this behavior.
As per the doc:
Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process.
The only thing I have in my config provision shell commands are installation commands. Nothing about wiping anything out.
I do have app.vm.provision for puppet that sets fqdn, user name and box name (along with the normal module_path, manifests_path and manifests_file). Maybe this caused things to be reset?
The Answer
Is Vagrant Provision suppose to wipe out all your data?
No. Vagrant should never harm your "data" (i.e., websites, code, etc.).
...now my whole guest box is wiped out. Is this normal?
Yes. Your Vagrant environment (in other words, the guest operating system created in a virtual environment by Vagrant) is volatile, and you should be able to destroy and recreate it at will without having any impact on your working files (because those should be kept in your local, or host, file system).
Explanation
On Vagrant's website, the very first thing they tell you is this:
Create and configure lightweight, reproducible, and portable development environments.
Your development environment allows you to work. You work on your data, in your development work environment. When you are done with your "development work environment," you should be able to delete it freely without affecting your data in the least.
Further, you should be able to send a collaborating developer your Vagrantfile so that they can create the exact same development environment you used to create your data (i.e., write your program, build your website, and so forth). Then, when you provide them with your code, they can use it in an environment identical to the one that your code was created in without having to reconfigure their own setup.
For more details about how your data files (code, working files, etc.) are kept safely in your computer while making them accessible to your guest system created by Vagrant, see my answer to this question.
So what appears to have happened was that when I set up a synced folder, it wiped out everything because there was nothing on my host machine in that synced folder. Unless there is a way to recover the lost data, there should be an unmistakable WARNING in their docs that this can happen.
I setup the synced_folder to be on my whole home directory. When I created a new machine, I cloned the one project I had saved and decided to just sync my individual projects instead of my whole user directory this time. When I reloaded, the project directory was empty since it was empty on my host machine.
So I guess, make sure the directories on your host machine are already setup with the data before configuring your Vagrantfile with synced_folder information.

Custom developer setup with Vagrant

I currently have a Vagrant vm with a typical web setup (apache, php, etc). The actual web repo is checked out onto the my local machine, and accessed through synced folders and forwarded apache ports (like http://127.0.0.1:4567/web). The question is, how do I make this work for a team, as opposed to just me? Since you have to sync folders, how is it possible for multiple devs to connect to one VM and sync folders?
I initially thought sharing the Vagrantfile would be all that is needed, but the Vagrantfile is agnostic to all apt-get commands and apache/php/node etc setup. I don't want devs to have to worry about running those.
This is what Vagrant provisioning is for.
Vagrant allows you to automatically alter configuration of a box or install additional software packages as a part of the first vagrant up process. Moreover, you can provision your system with various configuration management systems: Chef, Puppet, Ansible, CFEngine. Or you can simply use shell scripts.
Sitepoint offers a good tutorial on provisioning Ubuntu 14.04 box with bash scripts to install nginx, PHP-FPM and MySQL. Read it. Later you might want to move to configuration management systems.
Take a look at Phansible project which generates Ansible provisionings for PHP-based projects. Puppet provisioning for PHP-projects can be generated via PuPHPet. They will give you an idea how to use configuration management with Vagrant and might be used as s template for your Vagrantfile.
I always try to craft my Vagrantfiles carefully (provisioning, synced folder, for example, maps host's ./src/public onto /var/www/html/ on guest machine, port forwards and so on) so I can put them into project's root under version control. Later when my teammate clones project's repo on his machine he can issue vagrant up right away and get a fully functional development environment.
The only problem I haven't solved yet is updating existing VMs when new dependencies are added to projects. Now we update provisioning scripts and if developers encounter errors they manually reprovision their VMs by using vagrant reload --provision.
P.S. I asked a question regarding this problem

Is it possible to export/import a virtual box machine in one file?

I have a Vagrant set up with 3 virtual machines. Each machine has its own shell script for provisioning.
Now I would like to share the exact same status of my set up with somebody else. Since the provisioning procedure takes really (!!) long for each machine, I hope there is another solution.
Ideally I would be able to save each machine as it is in one file, which the other person then could import into Virtualbox. Is there a way to do that?
If I understand you correctly you would like to make a Vagrant base box from provisioned by Vagrant VMs. This is not recommended way to go. How you can approach this is:
Create new VM manually with required OS in the VBox.
Adjust it so Vagrant can connect to it as described here and here.
Provision it using your shell scripts.
Install all the things you would find useful to have on this VM.
Use Vagrant to package it as a base box as described here.
After packaging it with Vagrant you will get a Vagrant base box file with .box extension. You can then pass this to your team mates (usb, network share, ftp etc.) and they can add it to their Vagrant installation and use it. Whenever they will do Vagrant up they will get fully provisioned VM in VBox with all the stuff you have packaged to it. Vagrant also gives you versioning capabilities. If properly configured whenever you will create new version of base box everybody who is using it will be notified and would be able to download and use new version of your box.
Hope I understood your problem correctly and this will help to solve it.

Clarity on Vagrant usage and provisioning tool

Ok, so I'm a bit late jumping onto the Vagrant band-wagon, but figured it's about time I did.
Brief background: I've been a freelance developer for quite some time now developing solutions based on Magento and Drupal, and have finally gathered enough demand to warrant the need to build up a team. Previously, whenever I started development on any new project, I use to clone a preconfigured base VM in Virtualbox, and use that. Of course there were still configurations to do on it until I could start with actual development. Every project's web files therefore all resided inside /var/www/projectname on an Ubuntu VM.
Now I've read up on why I should be Vagrant, especially considering that I now have a team of 4 developers working with me, but I would appreciate any feedback on the following questions I have:
Moderator note: I know this isn't exactly asking a programming question, so please advise if this could be turned into a wiki, as I'm sure that feedback into this will help someone just like me.
I am still reading through the Vagrant docs, so please be kind...noob questions ahead!
I now work on a Mac. Does it matter if I use Parallels, and another developer uses VirtualBox on Windows if we need to share or collaborate on projects?
When I issue the command, vagrant up for an existing project, will it start the VM up as I would in VirtualBox or will it recreate the VM?
Is the command vagrant halt the same issuing sudo poweroff in Ubuntu, for example?
I currently use PhpStorm and its SFTP feature for project files synchronization with the option to exclude certain files on the remote server (VM) from being imported and sync'ed...will I be able to specify the same using Vagrant folder sharing?
Could I easily zip or archive a Vagrant VM, move it to a file server, and then "re-import" when and if needed? (example bug fixes, or new feature enhancements)
What do we use to easily provision VMs for common projects? Should we being using Puppet, Chef, Puphpet or Salt? I've seen that Puphpet provides a nice GUI to create a vagrantfile which I'm sure once generated, we could customize for future projects. At a very basic level, we need to ensure that certain applications are installed onto the server (zip, phpmyadmin, OpenSSL, etc.), certain PHP settings, PHP and PEAR modules, and Apache settings. I already have base VMs set up as I'd like them for both Magento projects as well as Drupal projects.
EDIT: I should also add that I use to enable Host Adapter in VirtualBox (on Windows), configure the VHost inside Ubuntu, and then update my host machine's hosts file with something like 192.168.56.3 drupalsite1.dev. So I'm unsure if Port Forwarding would be better to use? I'm not very clued up on that I must admit.
Like i said - noob questions! However, I would really appreciate any feedback on these questions. My deepest thanks!
Most of what you are asking is subjective so common sense and experience are the best tools.
I recommend all team members use the same provider (parallels isn't officially supported) and virtualbox is readily available. The base boxes, by provider, could have slight variances, you never know.
Vagrant will start the vm similarly but vagrant also does other things like configuration the network, hostname, shared folders, etc. Not quite the same. The big power lies in the capability to be able to teardown the environment and bring it back in a cleanly provisioned state.
Basically, yes.
Yes, your vagrant VMs are just like your own mini cloud. You would interact the servers similar to the way you'd interact with external boxes.
Yes, the simple answer is that it's called packaging and you can share the resultant .box. However, it's good practice to keep the base box and provisioning scripts under CM so you can rebuild and modify as needed.
For provisioners, I think it is dependent upon your experience and your familiarity with the provisioner language and how much you want to invest in learning them. Look through the provisioner support and see what fits your need and budget. Chef has a very steep learning curve, in my experience, but also has a lot of thought built in. Most provisioners have wide libraries of available installation "scripts".
The host adapter can be handled identically in vagrant.
Learn by doing, I recommend going down the table of contents (navbar) of the vagrant docs and trying each step where it makes sense. Then make your decisions.
That is my 2 cents. Hope this helps!

Resources